mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
add PrintSheet & ItemPool helper
This commit is contained in:
@@ -13,6 +13,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Write javadoc for this type.
|
* TODO: Write javadoc for this type.
|
||||||
@@ -68,6 +69,13 @@ public class PrintSheet {
|
|||||||
cardsWithWeights.remove(card);
|
cardsWithWeights.remove(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean contains(PaperCard pc) {
|
||||||
|
return cardsWithWeights.contains(pc);
|
||||||
|
}
|
||||||
|
public PaperCard find(Predicate<PaperCard> filter) {
|
||||||
|
return cardsWithWeights.find(filter);
|
||||||
|
}
|
||||||
|
|
||||||
private PaperCard fetchRoulette(int start, int roulette, Collection<PaperCard> toSkip) {
|
private PaperCard fetchRoulette(int start, int roulette, Collection<PaperCard> toSkip) {
|
||||||
int sum = start;
|
int sum = start;
|
||||||
boolean isSecondRun = start > 0;
|
boolean isSecondRun = start > 0;
|
||||||
@@ -85,15 +93,6 @@ public class PrintSheet {
|
|||||||
return fetchRoulette(sum + 1, roulette, toSkip); // start over from beginning, in case last cards were to skip
|
return fetchRoulette(sum + 1, roulette, toSkip); // start over from beginning, in case last cards were to skip
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperCard> all() {
|
|
||||||
List<PaperCard> result = new ArrayList<>();
|
|
||||||
for (Entry<PaperCard, Integer> kv : cardsWithWeights) {
|
|
||||||
for (int i = 0; i < kv.getValue(); i++) {
|
|
||||||
result.add(kv.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
public boolean containsCardNamed(String name,int atLeast) {
|
public boolean containsCardNamed(String name,int atLeast) {
|
||||||
int count=0;
|
int count=0;
|
||||||
for (Entry<PaperCard, Integer> kv : cardsWithWeights) {
|
for (Entry<PaperCard, Integer> kv : cardsWithWeights) {
|
||||||
@@ -144,7 +143,7 @@ public class PrintSheet {
|
|||||||
return cardsWithWeights.isEmpty();
|
return cardsWithWeights.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<PaperCard> toFlatList() {
|
public List<PaperCard> toFlatList() {
|
||||||
return cardsWithWeights.toFlatList();
|
return cardsWithWeights.toFlatList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ public class BoosterGenerator {
|
|||||||
|
|
||||||
if (sheetKey.startsWith("wholeSheet")) {
|
if (sheetKey.startsWith("wholeSheet")) {
|
||||||
PrintSheet ps = getPrintSheet(sheetKey);
|
PrintSheet ps = getPrintSheet(sheetKey);
|
||||||
result.addAll(ps.all());
|
result.addAll(ps.toFlatList());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,7 +384,7 @@ public class BoosterGenerator {
|
|||||||
PrintSheet replaceThis = tryGetStaticSheet(split[0]);
|
PrintSheet replaceThis = tryGetStaticSheet(split[0]);
|
||||||
List<PaperCard> candidates = Lists.newArrayList();
|
List<PaperCard> candidates = Lists.newArrayList();
|
||||||
for (PaperCard p : result) {
|
for (PaperCard p : result) {
|
||||||
if (replaceThis.all().contains(p)) {
|
if (replaceThis.contains(p)) {
|
||||||
candidates.add(candidates.size(), p);
|
candidates.add(candidates.size(), p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -398,7 +398,7 @@ public class BoosterGenerator {
|
|||||||
PrintSheet replaceThis = tryGetStaticSheet(split[0]);
|
PrintSheet replaceThis = tryGetStaticSheet(split[0]);
|
||||||
List<PaperCard> candidates = Lists.newArrayList();
|
List<PaperCard> candidates = Lists.newArrayList();
|
||||||
for (PaperCard p : result) {
|
for (PaperCard p : result) {
|
||||||
if (replaceThis.all().contains(p)) {
|
if (replaceThis.contains(p)) {
|
||||||
candidates.add(candidates.size(), p);
|
candidates.add(candidates.size(), p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -277,6 +277,10 @@ public class ItemPool<T extends InventoryItem> implements Iterable<Entry<T, Inte
|
|||||||
items.keySet().removeIf(filter.negate());
|
items.keySet().removeIf(filter.negate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T find(Predicate<T> filter) {
|
||||||
|
return items.keySet().stream().filter(filter).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
items.clear();
|
items.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user