Skip to content

Commit

Permalink
Various updates, add Monsters component.
Browse files Browse the repository at this point in the history
  • Loading branch information
phulin committed Sep 5, 2024
1 parent 3274eb9 commit b22be9b
Show file tree
Hide file tree
Showing 10 changed files with 519 additions and 171 deletions.
87 changes: 87 additions & 0 deletions client/src/components/Monsters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Text, Tooltip } from "@chakra-ui/react";
import {
appearanceRates,
getLocationMonsters,
isBanished,
Location,
Monster,
trackCopyCount,
trackIgnoreQueue,
} from "kolmafia";
import { $monster, getBanishedMonsters, sum } from "libram";

import { separate } from "../util/text";

export interface MonstersLineProps {
location: Location;
target: Monster | Monster[];
}

const Monsters: React.FC<MonstersLineProps> = ({ location, target }) => {
const targets = Array.isArray(target) ? target : [target];
const monsters = Object.keys(getLocationMonsters(location)).map((name) =>
Monster.get(name),
);
const appearingMonsters = monsters.filter(
(monster) =>
monster !== $monster`none` &&
appearanceRates(location)[monster.name] !== 0,
);
const queue = location.combatQueue
.split("; ")
.map((name) => Monster.get(name));

const monsterCopies = appearingMonsters.map((monster) => {
// TODO: Do banishes cancel out all copies? Or just Olfaction?
const copies = isBanished(monster) ? 0 : 1 + trackCopyCount(monster);
const reject = !trackIgnoreQueue(monster);
const copiesWithQueue =
(reject && queue.includes(monster) ? 0.25 : 1) * copies;
return { monster, copiesWithQueue };
});

const totalCopiesWithQueue = sum(
monsterCopies,
({ copiesWithQueue }) => copiesWithQueue,
);
const monsterFrequency = monsterCopies.map(
({ monster, copiesWithQueue }) => ({
monster,
frequency: copiesWithQueue / totalCopiesWithQueue,
}),
);

monsterFrequency.sort(({ monster: x }, { monster: y }) =>
targets.includes(x) ? -1 : targets.includes(y) ? 1 : 0,
);

return (
<>
Monsters:{" "}
{separate(
monsterFrequency.map(({ monster, frequency }) => {
const text = `${monster.name} (${queue.includes(monster) ? "Q " : ""}${(100 * frequency).toFixed(0)}%)`;
const banisher = [...getBanishedMonsters().entries()].find(
([, m]) => m === monster,
)?.[0];
return targets.includes(monster) ? (
<Text as="b">{text}</Text>
) : banisher ? (
<Tooltip hasArrow label={`Banished: ${banisher.name}`}>
<Text as="span" color="gray.500">
{text}
</Text>
</Tooltip>
) : (
text
);
}),
", ",
monsterFrequency.map(({ monster }) => monster.id),
)}
.
</>
);
};

export default Monsters;
2 changes: 1 addition & 1 deletion client/src/sections/QuestSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const QuestSection = () => {
!get("kingLiberated") && myPath() !== $path`Community Service`;
return (
<Section name="Quests">
<Manor />
{showStandardQuests && (
<>
<Manor />
<Level1 />
<Level2 />
<Level3 />
Expand Down
3 changes: 3 additions & 0 deletions client/src/sections/ResourceSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ import MiniKiwi from "./resources/2024/MiniKiwi";
import RomanCandelabra from "./resources/2024/RomanCandelabra";
import SpringShoes from "./resources/2024/SpringShoes";
import TearawayPants from "./resources/2024/TearawayPants";
import Banishes from "./resources/Banishes";
import FreeFights from "./resources/FreeFights";

// TODO: Organize by functionality, not release.
const ResourceSection = () => (
<Section name="Resources">
<FreeFights />
<Banishes />

{/* 2020 */}
<PowerfulGlove />
<Melodramedary />
Expand Down
17 changes: 13 additions & 4 deletions client/src/sections/quests/Level7.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import {
itemDropModifier,
monsterLevelAdjustment,
} from "kolmafia";
import { $item, get, have, questStep } from "libram";
import { $item, $location, $monster, get, have, questStep } from "libram";
import { ReactNode } from "react";

import Line from "../../components/Line";
import Monsters from "../../components/Monsters";
import QuestTile from "../../components/QuestTile";
import Tile from "../../components/Tile";
import { NagPriority } from "../../contexts/NagContext";
Expand All @@ -33,7 +35,7 @@ const getZoneDisplay = (
zone: string,
evil: number,
quickInfo: string,
zoneStrategy: string[],
zoneStrategy: ReactNode[],
): JSX.Element | undefined => {
if (evil > 0) {
return (
Expand All @@ -43,8 +45,10 @@ const getZoneDisplay = (
<Divider orientation="vertical" />
{evil > 25 ? (
<UnorderedList>
{zoneStrategy.map((strat) => (
<ListItem key={strat}>{strat}</ListItem>
{zoneStrategy.map((strat, index) => (
<ListItem key={typeof strat === "string" ? strat : index}>
{strat}
</ListItem>
))}
</UnorderedList>
) : (
Expand Down Expand Up @@ -117,6 +121,11 @@ const Level7 = () => {
])}
{getZoneDisplay("Niche", nicheEvil, "sniff dirty old lihc, banish", [
"banish all but dirty old lihc",
// TODO: Something wrong with this...
<Monsters
location={$location`The Defiled Niche`}
target={$monster`dirty old lihc`}
/>,
])}
{getZoneDisplay("Cranny", crannyEvil, "+ML, -combat", [
`~${Math.max(3, Math.sqrt(monsterLevelAdjustment())).toFixed(
Expand Down
9 changes: 8 additions & 1 deletion client/src/sections/quests/Level8.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { itemAmount, numericModifier, toItem } from "kolmafia";
import { $item, $location, get, have, questStep } from "libram";
import { $item, $location, $monster, get, have, questStep } from "libram";

import Line from "../../components/Line";
import Monsters from "../../components/Monsters";
import QuestTile from "../../components/QuestTile";
import faxLikes from "../../util/faxLikes";
import { atStep, Step } from "../../util/quest";
Expand Down Expand Up @@ -62,6 +63,12 @@ const Level8: React.FC = () => {
)}
.
</Line>
{goatCheese < 3 && (
<Monsters
location={$location`The Goatlet`}
target={$monster`dairy goat`}
/>
)}
{ore < 3 && faxLikes.length > 0 && (
<Line>Could use {commaOr(faxLikes())} for a mountain man.</Line>
)}
Expand Down
Loading

0 comments on commit b22be9b

Please sign in to comment.