mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
simplify ConquestAwardPool
This commit is contained in:
@@ -3,16 +3,15 @@ package forge.planarconquest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import forge.item.PaperCard;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
public class ConquestAwardPool {
|
||||
private final BoosterPool commons, uncommons, rares, mythics;
|
||||
public final List<PaperCard> commons, uncommons, rares, mythics;
|
||||
|
||||
public ConquestAwardPool(Iterable<PaperCard> cards) {
|
||||
commons = new BoosterPool();
|
||||
uncommons = new BoosterPool();
|
||||
rares = new BoosterPool();
|
||||
mythics = new BoosterPool();
|
||||
commons = new ArrayList<PaperCard>();
|
||||
uncommons = new ArrayList<PaperCard>();
|
||||
rares = new ArrayList<PaperCard>();
|
||||
mythics = new ArrayList<PaperCard>();
|
||||
|
||||
for (PaperCard c : cards) {
|
||||
switch (c.getRarity()) {
|
||||
@@ -34,41 +33,4 @@ public class ConquestAwardPool {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BoosterPool getCommons() {
|
||||
return commons;
|
||||
}
|
||||
public BoosterPool getUncommons() {
|
||||
return uncommons;
|
||||
}
|
||||
public BoosterPool getRares() {
|
||||
return rares;
|
||||
}
|
||||
public BoosterPool getMythics() {
|
||||
return mythics;
|
||||
}
|
||||
|
||||
public class BoosterPool {
|
||||
private final List<PaperCard> cards = new ArrayList<PaperCard>();
|
||||
|
||||
private BoosterPool() {
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return cards.isEmpty();
|
||||
}
|
||||
|
||||
private void add(PaperCard c) {
|
||||
cards.add(c);
|
||||
}
|
||||
|
||||
public void rewardCard(List<PaperCard> rewards) {
|
||||
if (isEmpty()) { return; }
|
||||
|
||||
int index = Aggregates.randomInt(0, cards.size() - 1);
|
||||
PaperCard c = cards.get(index);
|
||||
cards.remove(index);
|
||||
rewards.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,23 +200,19 @@ public class ConquestController {
|
||||
int boostersPerMythic = prefs.getPrefInt(CQPref.BOOSTERS_PER_MYTHIC);
|
||||
int raresPerBooster = prefs.getPrefInt(CQPref.BOOSTER_RARES);
|
||||
for (int i = 0; i < raresPerBooster; i++) {
|
||||
if (pool.getMythics().isEmpty() || Aggregates.randomInt(1, boostersPerMythic) > 1) {
|
||||
pool.getRares().rewardCard(rewards);
|
||||
}
|
||||
else {
|
||||
pool.getMythics().rewardCard(rewards);
|
||||
}
|
||||
if (!pool.mythics.isEmpty() && Aggregates.randomInt(1, boostersPerMythic) == 1)
|
||||
rewards.add(Aggregates.removeRandom(pool.mythics));
|
||||
else if(!pool.rares.isEmpty())
|
||||
rewards.add(Aggregates.removeRandom(pool.rares));
|
||||
}
|
||||
|
||||
int uncommonsPerBooster = prefs.getPrefInt(CQPref.BOOSTER_UNCOMMONS);
|
||||
for (int i = 0; i < uncommonsPerBooster; i++) {
|
||||
pool.getUncommons().rewardCard(rewards);
|
||||
}
|
||||
for (int i = 0; i < uncommonsPerBooster && !pool.uncommons.isEmpty(); i++)
|
||||
rewards.add(Aggregates.removeRandom(pool.uncommons));
|
||||
|
||||
int commonsPerBooster = prefs.getPrefInt(CQPref.BOOSTER_COMMONS);
|
||||
for (int i = 0; i < commonsPerBooster; i++) {
|
||||
pool.getCommons().rewardCard(rewards);
|
||||
}
|
||||
for (int i = 0; i < commonsPerBooster && !pool.commons.isEmpty(); i++)
|
||||
rewards.add(Aggregates.removeRandom(pool.commons));
|
||||
|
||||
BoosterUtils.sort(rewards);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user