Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support snapper as a familiar #1578

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
34 changes: 32 additions & 2 deletions src/familiar/freeFightFamiliar.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { Familiar, familiarWeight, inebrietyLimit, Location, myInebriety } from "kolmafia";
import { $familiar, $item, $location, clamp, findLeprechaunMultiplier, get, have } from "libram";
import { Familiar, familiarWeight, inebrietyLimit, Location, Monster, myInebriety } from "kolmafia";
import {
$familiar,
$item,
$location,
$phylum,
clamp,
findLeprechaunMultiplier,
get,
have,
Snapper,
} from "libram";
import { canOpenRedPresent } from ".";
import { garboValue } from "../value";
import getConstantValueFamiliars from "./constantValueFamiliars";
import getDropFamiliars from "./dropFamiliars";
import getExperienceFamiliars from "./experienceFamiliars";
import { GeneralFamiliar, timeToMeatify } from "./lib";
import { meatFamiliar } from "./meatFamiliar";
import { barfEncounterRate } from "../lib";

type MenuOptions = {
canChooseMacro?: boolean;
Expand Down Expand Up @@ -69,6 +80,25 @@ export function menu(options: MenuOptions = {}): GeneralFamiliar[] {
limit: "special",
});
}
if (
location === $location`Barf Mountain` &&
Snapper.have() &&
Snapper.getTrackedPhylum() === $phylum`dude`
) {
const encounterRate = barfEncounterRate({ snapper: true, snapperPhylum: $phylum`dude` });
const dudeRate = [...encounterRate.entries()].reduce(
(acc: number, entry: [Monster, number]) =>
entry[0].phylum === $phylum`dude` ? entry[1] + acc : acc,
0,
);

Comment on lines +89 to +93
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const dudeRate = [...encounterRate.entries()].reduce(
(acc: number, entry: [Monster, number]) =>
entry[0].phylum === $phylum`dude` ? entry[1] + acc : acc,
0,
);
const dudeRate = sum([...encounterRate.entries()], ([monster, weight]) => monster.phylum === $phylum`dude` ? weight : 0);

familiarMenu.push({
familiar: $familiar`Red-Nosed Snapper`,
expectedValue: (dudeRate * garboValue($item`human musk`)) / 11,
leprechaunMultiplier: 0,
limit: "none",
});
}
}

const meatFam = meatFamiliar();
Expand Down
5 changes: 4 additions & 1 deletion src/fights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import {
Requirement,
Robortender,
set,
Snapper,
SourceTerminal,
sum,
tryFindFreeRun,
Expand Down Expand Up @@ -994,7 +995,9 @@ const freeFightSources = [
new FreeFight(
() => (wantPills() ? 5 - get("_saberForceUses") : 0),
() => {
if (have($familiar`Red-Nosed Snapper`)) cliExecute(`snapper ${$phylum`dude`}`);
if (Snapper.have() && Snapper.getTrackedPhylum() !== $phylum`dude`) {
Snapper.trackPhylum($phylum`dude`);
}
setChoice(1387, 3);
if (
have($skill`Comprehensive Cartography`) &&
Expand Down
81 changes: 81 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
mySoulsauce,
myTurncount,
numericModifier,
Phylum,
print,
printHtml,
restoreHp,
Expand All @@ -60,6 +61,8 @@ import {
$item,
$location,
$monster,
$monsters,
$phylum,
$skill,
$slot,
ActionSource,
Expand All @@ -80,6 +83,7 @@ import {
PropertiesManager,
property,
set,
Snapper,
SongBoom,
sum,
uneffect,
Expand Down Expand Up @@ -683,3 +687,80 @@ export function printEventLog(): void {
);
}
}

const rateCache = new Map<string, Map<Monster, number>>();

export function barfEncounterRate(options: {
snapper?: boolean;
snapperPhylum?: Phylum;
olfact?: Monster;
longCon?: Monster;
motif?: Monster;
turtle?: Monster;
monkeyPoint?: Monster;
humanity?: boolean;
}): Map<Monster, number> {
Comment on lines +693 to +702
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just make this a Partial

const olfact = options.olfact ?? get("olfactedMonster");
const longCon = options.longCon ?? get("longConMonster");
const motif = options.motif ?? get("motifMonster");
const turtle = options.turtle ?? get("_gallapagosMonster");
const monkeyPoint = options.monkeyPoint ?? get("monkeyPointMonster");
const snapper = options.snapper ?? myFamiliar() === $familiar`Red-Nosed Snapper`;
const snapperPhylum = options.snapperPhylum ?? Snapper.getTrackedPhylum();
const humanity = options.humanity ?? have($effect`Ew, The Humanity`);
horrible-little-slime marked this conversation as resolved.
Show resolved Hide resolved

const zoneMonsters = $monsters`garbage tourist, angry tourist, horrible tourist family`;
const encounterQueue = zoneMonsters.filter((m) =>
$location`Barf Mountain`.combatQueue.includes(`${m}`),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer m.name here but I think using the template literal below makes sense so maybe being consistent within this area is better

);

const cacheKey = [
olfact,
longCon,
motif,
turtle,
monkeyPoint,
snapper,
snapperPhylum,
humanity,
...encounterQueue,
]
.map((v) => `${v}`)
.join(":");

const cachedValue = rateCache.get(cacheKey);
if (cachedValue) {
return cachedValue;
}
Comment on lines +732 to +734
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (cachedValue) {
return cachedValue;
}
if (cachedValue) return cachedValue;


const copies = (target: Monster | null, n: number): Monster[] =>
n === 0 ? [] : [...zoneMonsters.filter((m) => m === target), ...copies(target, n - 1)];
Comment on lines +736 to +737
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like a .fill solution will be more performant and legible than the recursive one


const monsterQueue = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this the CSV, not the queue. Or call it some other thing. But don't call it the queue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

monsterPool?

...zoneMonsters,
...copies(olfact, 3),
...copies(longCon, 3),
...copies(motif, 2),
...copies(turtle, 1),
...copies(monkeyPoint, 2),
...zoneMonsters
.filter((m) => snapper && m.phylum === snapperPhylum)
.flatMap((m) => copies(m, 2)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have had trouble with polyfilling flatMap before; definitely make sure this works the way you want it to

...zoneMonsters
.filter((m) => humanity && m.phylum === $phylum`dude`)
.flatMap((m) => copies(m, 2)),
];

const encounters = monsterQueue.flatMap((m) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this variable is meant to represent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update: I think I might understand it, but if I do then it's not quite right: we only reroll 75% of the time, but even a reroll can reroll.

This math is really hard to do--slaw wrote a big ol' thesis about it. I think we have to do it numerically instead of analytically.

monsterQueue.map((n) =>
// olfaction, longcon, and motif caus that monster to ignore queue rejection
olfact === m || longCon === m || motif === m || !encounterQueue.includes(m) ? m : n,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
olfact === m || longCon === m || motif === m || !encounterQueue.includes(m) ? m : n,
[olfact, longCon, motif].includes(m) && !encounterQueue.includes(m) ? m : n,

),
);

const encounterRate = new Map<Monster, number>(
zoneMonsters.map((m) => [m, encounters.filter((n) => n === m).length / encounters.length]),
);
rateCache.set(cacheKey, encounterRate);
return encounterRate;
}
8 changes: 8 additions & 0 deletions src/tasks/dailyFamiliars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import {
$familiars,
$item,
$items,
$phylum,
CrimboShrub,
get,
have,
Robortender,
set,
Snapper,
sum,
withProperty,
} from "libram";
Expand Down Expand Up @@ -227,6 +229,12 @@ const DailyFamiliarTasks: GarboTask[] = [
!!get("garbo_felizValue", 0) || today - get("garbo_felizValueDate", 0) < 24 * 60 * 60 * 1000,
do: () => felizValue,
},
{
name: "Snapper Hunts Dudes",
ready: () => Snapper.have(),
completed: () => Snapper.getTrackedPhylum() === $phylum`dude`,
do: () => Snapper.trackPhylum($phylum`dude`),
},
];

export const DailyFamiliarsQuest: Quest<GarboTask> = {
Expand Down
Loading