Skip to content

Commit

Permalink
Minor improvements (#92)
Browse files Browse the repository at this point in the history
* Move to tsx. Hopefully the last time we change this

* Factor out common pattern in projects of "do I have this item equipped at the end of combat"
  • Loading branch information
gausie committed Jun 19, 2024
1 parent aacd03b commit ff8b1be
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 281 deletions.
16 changes: 9 additions & 7 deletions packages/excavator-projects/projects/designerSweatpants.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { currentRound, Item, equippedItem, Slot, myLocation } from "kolmafia";
import { Item, myLocation } from "kolmafia";

import { ExcavatorProject } from "../type";
import { shouldDiscardData, toNormalisedString } from "../utils";
import {
isEquippedAtEndOfCombat,
shouldDiscardData,
toNormalisedString,
} from "../utils";

function spadeSweatpants(encounter: string, page: string) {
if (currentRound() !== 0) return null;
if (
!Item.get(["designer sweatpants", "replica designer sweatpants"]).includes(
equippedItem(Slot.get("pants")),
!isEquippedAtEndOfCombat(
Item.get(["designer sweatpants", "replica designer sweatpants"]),
)
) {
)
return null;
}

const sweat = Number(page.match(/You get (\d)% Sweatier/)?.[1]);
if (!sweat) return null;
Expand Down
9 changes: 3 additions & 6 deletions packages/excavator-projects/projects/dropConSnowglobe.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "core-js/modules/es.string.match-all";
import { currentRound, equippedAmount, Item } from "kolmafia";
import { Item } from "kolmafia";

import { ExcavatorProject } from "../type";
import { toNormalisedItem } from "../utils";
import { isEquippedAtEndOfCombat, toNormalisedItem } from "../utils";

export const DROP_CON_SNOWGLOBE: ExcavatorProject = {
name: "KoL Con 13 Snowglobe",
Expand Down Expand Up @@ -72,10 +72,7 @@ function spadeSnowglobe(
encounter: string,
page: string,
): SnowglobeData[] | null {
// Must be end of battle
if (currentRound() !== 0) return null;
// Must be wearing KoL Con 13 snowglobe
if (equippedAmount(Item.get("KoL Con 13 snowglobe")) < 1) return null;
if (!isEquippedAtEndOfCombat(Item.get("KoL Con 13 snowglobe"))) return null;

const data = [];

Expand Down
8 changes: 3 additions & 5 deletions packages/excavator-projects/projects/dropMixedEverything.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { currentRound, equippedAmount, Item } from "kolmafia";

import { ExcavatorProject } from "../type";
import { toNormalisedItem } from "../utils";
import { isEquippedAtEndOfCombat, toNormalisedItem } from "../utils";

export const DROP_MIXED_EVERYTHING: ExcavatorProject = {
name: "Can Of Mixed Everything",
description: "Track drops from the can of mixed everything.",
author: "Rinn",
hooks: {
COMBAT_ROUND: (encounter: string, page: string) => {
// Must be end of battle
if (currentRound() !== 0) return null;
// Must be wearing the can of mixed everything
if (equippedAmount(Item.get("can of mixed everything")) < 1) return null;
if (!isEquippedAtEndOfCombat(Item.get("can of mixed everything")))
return null;
const result = page.match(
/Something falls out of your can of mixed everything.*?You acquire an item: <b>(.*?)<\/b>/,
);
Expand Down
10 changes: 4 additions & 6 deletions packages/excavator-projects/projects/dropMrCheengs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { currentRound, equippedAmount, Item } from "kolmafia";
import { Item } from "kolmafia";

import { ExcavatorProject } from "../type";
import { toNormalisedItem } from "../utils";
import { isEquippedAtEndOfCombat, toNormalisedItem } from "../utils";

export const DROP_MR_CHEENGS: ExcavatorProject = {
name: "Mr. Cheeng's Spectacles",
Expand All @@ -10,10 +10,8 @@ export const DROP_MR_CHEENGS: ExcavatorProject = {
author: "Rinn",
hooks: {
COMBAT_ROUND: (encounter: string, page: string) => {
// Must be end of battle
if (currentRound() !== 0) return null;
// Must be wearing Mr. Cheeng's spectacles
if (equippedAmount(Item.get("Mr. Cheeng's spectacles")) < 1) return null;
if (!isEquippedAtEndOfCombat(Item.get("Mr. Cheeng's spectacles")))
return null;
const result = page.match(
/You see a weird thing out of the corner of your eye, and you grab it.\s+Far out, man!.*?You acquire an item: <b>(.*?)<\/b>/,
);
Expand Down
8 changes: 3 additions & 5 deletions packages/excavator-projects/projects/dropMrScreeges.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { currentRound, equippedAmount, Item } from "kolmafia";

import { ExcavatorProject } from "../type";
import { toNormalisedItem } from "../utils";
import { isEquippedAtEndOfCombat, toNormalisedItem } from "../utils";

export const DROP_MR_SCREEGES: ExcavatorProject = {
name: "Mr. Screege's Spectacles",
Expand All @@ -10,10 +10,8 @@ export const DROP_MR_SCREEGES: ExcavatorProject = {
author: "Rinn",
hooks: {
COMBAT_ROUND: (encounter: string, page: string) => {
// Must be end of battle
if (currentRound() !== 0) return null;
// Must be wearing Mr. Screege's spectacles
if (equippedAmount(Item.get("Mr. Screege's spectacles")) < 1) return null;
if (!isEquippedAtEndOfCombat(Item.get("Mr. Screege's spectacles")))
return null;
const result = page.match(
/You notice something valuable hidden .*?You acquire an item: <b>(.*?)<\/b>/,
);
Expand Down
8 changes: 4 additions & 4 deletions packages/excavator-projects/projects/outOfOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "kolmafia";

import { ExcavatorProject } from "../type";
import { isEquippedAtEndOfCombat } from "../utils";

export const OUT_OF_ORDER: ExcavatorProject = {
name: "Out of Order",
Expand All @@ -20,10 +21,9 @@ export const OUT_OF_ORDER: ExcavatorProject = {
COMBAT_ROUND: (encounter: string, page: string) => {
// Must be on the quest
if (getProperty("questEspOutOfOrder") === "unstarted") return null;
// Must be end of battle
if (currentRound() !== 0) return null;
// Must be wearing the wristwatch
if (equippedAmount(Item.get("GPS-tracking wristwatch")) < 1) return null;
// Must be equipped and at the end of a combat
if (!isEquippedAtEndOfCombat(Item.get("GPS-tracking wristwatch")))
return null;
// Must be in the jungle
if (myLocation() !== Location.get("The Deep Dark Jungle")) return null;
const beeps = page.match(
Expand Down
7 changes: 3 additions & 4 deletions packages/excavator-projects/projects/summonMayflySwarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "kolmafia";

import { ExcavatorProject } from "../type";
import { isEquippedAtEndOfCombat } from "../utils";

const ZONE_PATTERNS = new Map<string, RegExp>([
[
Expand Down Expand Up @@ -76,10 +77,8 @@ export const SUMMON_MAYFLY_SWARM: ExcavatorProject = {
author: "Rinn",
hooks: {
COMBAT_ROUND: (_: string, page: string) => {
// Must be end of battle
if (currentRound() !== 0) return null;
// Must be wearing mayfly bait necklace
if (equippedAmount(Item.get("mayfly bait necklace")) < 1) return null;
if (!isEquippedAtEndOfCombat(Item.get("mayfly bait necklace")))
return null;
// Must be in a tracked zone or location
const specialPattern =
ZONE_PATTERNS.get(myLocation().zone) ??
Expand Down
8 changes: 8 additions & 0 deletions packages/excavator-projects/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
canInteract,
currentRound,
Effect,
equippedAmount,
gamedayToInt,
getProperty,
haveEffect,
Expand Down Expand Up @@ -102,3 +104,9 @@ export function shouldDiscardData(property: string, data: string) {
sessionStorage.setItem(property, [...sentData, data].join("|"));
return false;
}

export function isEquippedAtEndOfCombat(item: Item | Item[]) {
if (currentRound() !== 0) return false;
const items = Array.isArray(item) ? item : [item];
return items.some((i) => equippedAmount(i) > 0);
}
10 changes: 5 additions & 5 deletions packages/excavator-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"type": "module",
"scripts": {
"build": "remix vite:build",
"dev": "node --loader tsm ./server.ts",
"start": "NODE_ENV=production node --loader tsm ./server.ts",
"etl": "node --loader tsm ./etl.ts",
"dev": "node --import tsx ./server.ts",
"start": "NODE_ENV=production node --import tsx ./server.ts",
"etl": "node --import tsx ./etl.ts",
"format": "prettier --write .",
"lint": "prettier --check ."
},
Expand All @@ -32,7 +32,8 @@
"isbot": "5.1.9",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"spin-delay": "^2.0.0"
"spin-delay": "^2.0.0",
"tsx": "^4.15.6"
},
"devDependencies": {
"@remix-run/dev": "^2.9.2",
Expand All @@ -43,7 +44,6 @@
"excavator-prettier-config": "^0.0.0",
"prettier": "^3.3.2",
"prisma": "^5.15.0",
"tsm": "^2.3.0",
"typescript": "^5.4.5",
"vite": "^5.3.1"
},
Expand Down
Loading

0 comments on commit ff8b1be

Please sign in to comment.