Skip to content

Commit

Permalink
Merge branch 'main' into splitmodifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
horrible-little-slime authored Nov 13, 2024
2 parents 2ba28fd + 6b53ded commit a3f6c1f
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 2 deletions.
62 changes: 62 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1470,3 +1470,65 @@ export function totalFamiliarWeight(
(familiar.feasted ? 10 : 0)
);
}

export const familiarTags = Object.freeze([
"animal",
"insect",
"haseyes",
"haswings",
"fast",
"bite",
"flies",
"hashands",
"wearsclothes",
"organic",
"vegetable",
"hovers",
"edible",
"food",
"sentient",
"cute",
"mineral",
"polygonal",
"object",
"undead",
"cantalk",
"evil",
"orb",
"spooky",
"sleaze",
"aquatic",
"swims",
"isclothes",
"phallic",
"stench",
"hot",
"hasbeak",
"haslegs",
"robot",
"technological",
"hard",
"cold",
"hasbones",
"hasclaws",
"reallyevil",
"good",
"person",
"humanoid",
"animatedart",
"software",
"pokefam",
"hasshell",
"hasstinger",
] as const);

export type FamiliarTag = (typeof familiarTags)[number];

/**
* Find the tags (used in mumming trunk, stillsuit, etc) for a given familiar
* @param familiar The familiar in question
* @returns An array of the familiar's tags
*/
export function getFamiliarTags(familiar: Familiar): FamiliarTag[] {
return familiar.attributes.split("; ").filter(Boolean) as FamiliarTag[];
}
95 changes: 93 additions & 2 deletions src/resources/2022/Stillsuit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { cliExecute, splitModifiers, visitUrl } from "kolmafia";
import { have as haveItem } from "../../lib.js";
import { cliExecute, Familiar, splitModifiers, visitUrl } from "kolmafia";
import { FamiliarTag, getFamiliarTags, have as haveItem } from "../../lib.js";
import { get } from "../../property.js";
import { $item } from "../../template-string.js";
import { NumericModifier } from "../../modifierTypes.js";
import { Modifiers, parseModifiers } from "../../modifier.js";
import { StringProperty } from "../../propertyTypes.js";
import { maxBy } from "../../utils.js";

/**
* Do you own a still-suit?
Expand Down Expand Up @@ -62,3 +63,93 @@ export function distillateModifier(modifier: NumericModifier): number {
const value = splitModifiers("currentDistillateMods")[modifier];
return value ? Number(value) : 0;
}

type StillsuitTag = Exclude<FamiliarTag, "pokefam">;

export const MODIFIER_TAGS: Record<StillsuitTag, NumericModifier> =
Object.freeze({
mineral: "Muscle",
robot: "Muscle",
organic: "Muscle",
hasbones: "Muscle",
technological: "Mysticality",
orb: "Mysticality",
sentient: "Mysticality",
polygonal: "Mysticality",
software: "Mysticality",
cantalk: "Mysticality",
humanoid: "Moxie",
hashands: "Moxie",
cute: "Moxie",
good: "Moxie",
phallic: "Moxie",
animatedart: "Moxie",
person: "Moxie",
haseyes: "Item Drop",
object: "Item Drop",
haslegs: "Item Drop",
food: "Food Drop",
vegetable: "Food Drop",
edible: "Food Drop",
animal: "Damage Reduction",
insect: "Damage Reduction",
wearsclothes: "Damage Reduction",
isclothes: "Damage Reduction",
hasshell: "Damage Reduction",
haswings: "Initiative",
fast: "Initiative",
flies: "Initiative",
hovers: "Initiative",
swims: "Initiative",
aquatic: "Initiative",
spooky: "Spooky Damage",
undead: "Spooky Damage",
evil: "Spooky Damage",
reallyevil: "Spooky Damage",
hot: "Hot Damage",
cold: "Cold Damage",
sleaze: "Sleaze Damage",
stench: "Stench Damage",
bite: "Weapon Damage",
hasclaws: "Weapon Damage",
hasbeak: "Weapon Damage",
hasstinger: "Weapon Damage",
hard: "Weapon Damage",
} as const);

function isStillsuitTag(tag: string): tag is StillsuitTag {
return tag in MODIFIER_TAGS;
}

/**
* Calculate the ratio of stillsuit modifiers for a particular familiar.
* @param familiar The familiar in question
* @returns An object whose keys are NumericModifiers potentially granted by the stillsuit distillate from this familiar, and whose values are the relative weights of those modifiers
*/
export function modifierRatio(
familiar: Familiar,
): Partial<Record<NumericModifier, number>> {
const tags = getFamiliarTags(familiar);
return tags
.filter(isStillsuitTag)
.reduce<Partial<Record<NumericModifier, number>>>(
(acc, tag) => ({
...acc,
[MODIFIER_TAGS[tag]]:
((acc[MODIFIER_TAGS[tag]] ?? 0) + 1) / tags.length,
}),
{},
);
}

/**
* Identify the best familiar you have to generate stillsuit distillate for a given modifier
* @param modifier The modifier in question
* @returns The familiar you currently `have` that returns the best stillsuit distillate for that modifier.
*/
export function bestFamiliar(modifier: NumericModifier): Familiar {
return maxBy(
Familiar.all().filter(have),
(familiar) => modifierRatio(familiar)[modifier] ?? 0,
);
}

0 comments on commit a3f6c1f

Please sign in to comment.