Skip to content

Commit

Permalink
🐛 resolve magic/monster variants before reprints
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Dec 13, 2024
1 parent cbc6644 commit 9dbe233
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ public void prepare() {

tui().progressf("Resolving copies and link sources");

// Find remaining/included base items
List<JsonNode> baseItems = nodeIndex.values().stream()
.filter(n -> TtrpgValue.indexBaseItem.booleanOrDefault(n, false))
.filter(n -> !ItemField.packContents.existsIn(n))
.toList();

Map<String, JsonNode> variants = new HashMap<>();

// For each node: handle copies, link sources
for (Entry<String, JsonNode> entry : nodeIndex.entrySet()) {
String key = entry.getKey();
Expand Down Expand Up @@ -344,8 +352,20 @@ public void prepare() {
default -> {
}
}

// Reprints do follow specialized variants, so we need to find the variants
// now (and will filter them out based on rules later...)
if (type.hasVariants()) {
List<Tuple> variantList = findVariants(key, jsonSource, baseItems);
for (Tuple variant : variantList) {
variants.put(variant.key, variant.node);
}
}
} // end for each entry

nodeIndex.putAll(variants);
variants.clear();

filteredIndex = new HashMap<>(nodeIndex.size());

tui().progressf("Applying source filters");
Expand All @@ -362,7 +382,8 @@ public void prepare() {
for (var e : nodeIndex.entrySet()) {
String key = e.getKey();
Tools5eIndexType type = Tools5eIndexType.getTypeFromKey(key);
Tools5eSources sources = Tools5eSources.findSources(key);
// construct source if missing (which it may be for a variant)
Tools5eSources sources = Tools5eSources.constructSources(key, e.getValue());
Msg msgType = sources.filterRuleApplied() ? Msg.TARGET : Msg.FILTER;

if (type.isFluffType()) {
Expand All @@ -387,26 +408,6 @@ public void prepare() {
tui().progressf("Removing dependent and dangling resources");
filteredIndex.keySet().removeIf(k -> otherwiseExcluded(k));

// After we've removed reprints and otherwise excluded items,
// let's generate variants for monsters and magic items

tui().progressf("Populating variants");

// Find remaining/included base items
List<JsonNode> baseItems = filteredIndex.values().stream()
.filter(n -> TtrpgValue.indexBaseItem.booleanOrDefault(n, false))
.filter(n -> !ItemField.packContents.existsIn(n))
.toList();

// Find variant nodes (magic items, monsters)
List<Tuple> variantNodes = filteredIndex.entrySet().stream()
.filter(e -> Tools5eIndexType.getTypeFromKey(e.getKey()).hasVariants())
.flatMap(e -> findVariants(e.getKey(), e.getValue(), baseItems).stream())
.toList();

// Add the variants back into the index, which may replace the original
variantNodes.forEach(t -> filteredIndex.put(t.key, t.node));

// Deities have their own glorious reprint mess, which we only need to deal with
// when we aren't hoarding all the things.
if (config.reprintBehavior() != ReprintBehavior.all) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/convertData.json
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@
"item|shield, +1|dmg": "item|+1 shield|dmg",
"item|thieves tools|phb": "item|thieves' tools|phb",
"item|wands of magic missiles|dmg": "item|wand of magic missiles|dmg",
"itemgroup|spell scroll|xphb": "itemgroup|spell scroll|xdmg",
"spell|acid arrow|phb": "spell|melf's acid arrow|phb",
"spell|bane spell|phb": "spell|bane|phb",
"spell|ceremony|phb": "spell|ceremony|xge",
Expand Down

0 comments on commit 9dbe233

Please sign in to comment.