Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Args } from "grimoire-kolmafia";
import { Effect, Modifier, myPath, print, toEffect, toModifier } from "kolmafia";
import { Effect, Modifier, myPath, print, toEffect } from "kolmafia";
import { $effects, $path, get, have, NumericModifier, sinceKolmafiaRevision } from "libram";
import {
findOptimalOutfitPower,
Expand Down Expand Up @@ -71,14 +71,12 @@ function parseWeightedModifiers(input: string): Partial<Record<NumericModifier,

for (const part of parts) {
// Try to match weighted, e.g. "5 Meat Drop"
const weightedMatch = part.match(/^(\d+)\s+(.+)$/);
const weightedMatch = part.match(/^(-)?(\d+)?\s*(.+)$/);
if (weightedMatch) {
const weight = Number(weightedMatch[1]);
const modifierName = weightedMatch[2].trim() as NumericModifier;
result[modifierName] = weight;
} else {
// Default weight 1 for singular modifier e.g. "Meat Drop"
result[part as NumericModifier] = 1;
const sign = weightedMatch[1] === "-" ? -1 : 1;
const weight = weightedMatch[2] === undefined ? 1 : Number(weightedMatch[2]);
const modifierName = weightedMatch[3].trim() as NumericModifier;
result[modifierName] = sign * weight;
}
}
return result;
Expand Down Expand Up @@ -154,10 +152,6 @@ export function main(command?: string): void {
.join(", ")}]`
);

printBuskResult(
result,
Object.keys(weightedModifiers).map((mod) => toModifier(mod)),
desiredEffects
);
printBuskResult(result, weightedModifiers, desiredEffects);
}
}
17 changes: 11 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
print,
Slot,
toEffect,
toModifier,
toSlot,
} from "kolmafia";
import {
Expand Down Expand Up @@ -73,7 +74,7 @@ function multipliers(slot: Slot): number {

export function printBuskResult(
result: BuskResult | null,
modifiers: Modifier[],
modifiers: Partial<Record<NumericModifier, number>>,
desiredEffects: Effect[] = []
): void {
if (!result) {
Expand All @@ -94,13 +95,15 @@ export function printBuskResult(
$modifier`Familiar Experience`,
];

const modKeys = Object.keys(modifiers).map((mod) => toModifier(mod));

for (const { effects, daRaw, buskIndex } of bestBusks) {
const desiredMatches = effects.filter((e) => desiredEffects.includes(e));
print(`Power ${daRaw} Busk ${buskIndex + 1}`);

// Calculate total buff per weighted modifier
const weightedTotals = new Map<Modifier, number>();
for (const mod of modifiers) {
for (const mod of modKeys) {
const total = sum(effects, (ef) => numericModifier(ef, mod));
weightedTotals.set(mod, total);
}
Expand All @@ -120,8 +123,10 @@ export function printBuskResult(
print(`Total buffs: ${totalBuffsStr}`);

// For each weighted modifier, print contributing effects
for (const mod of modifiers) {
const contributingEffects = effects.filter((e) => numericModifier(e, mod) > 0);
for (const mod of modKeys) {
const contributingEffects = effects.filter(
(e) => numericModifier(e, mod) * modifiers[mod.name as NumericModifier]! > 0
);
if (contributingEffects.length === 0) continue;

print(`${mod.name}:`);
Expand All @@ -130,7 +135,7 @@ export function printBuskResult(

// Optionally print other useful modifiers if args.othermodifiers is true
if (othermodifiers) {
const otherMods = otherModifiersList.filter((mod) => !modifiers.includes(mod));
const otherMods = otherModifiersList.filter((mod) => !modKeys.includes(mod));
if (otherMods.length > 0) {
print(`Other Useful Modifiers:`);
for (const mod of otherMods) {
Expand All @@ -142,7 +147,7 @@ export function printBuskResult(
}
}
const usefulEffects = effects.filter((e) =>
modifiers.some((mod) => numericModifier(e, mod) > 0)
modKeys.some((mod) => numericModifier(e, mod) * modifiers[mod.name as NumericModifier]! > 0)
);
const otherEffects = effects.filter(
(e) => !desiredEffects.includes(e) && !usefulEffects.includes(e)
Expand Down