Skip to content

Commit 8138ba6

Browse files
committed
✨ Log manual fishing.
This is mostly for other people.
1 parent 23b50a5 commit 8138ba6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/fishing.js

+30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { fetchInventory } from './inventory.js'
22

3+
const fishCaughtItemRE = /<br\/>(.*?)\s*$/
4+
35
const parseNetResults = (page, url) => {
46
const results = {items: []}
57
// Parse the ID out of the URL.
@@ -66,8 +68,36 @@ const visitSellAllUserFish = async (state, page, url) => {
6668
await fetchInventory(state)
6769
}
6870

71+
const parseFishCaught = (page, url) => {
72+
const results = {}
73+
// Parse the ID out of the URL.
74+
const parsedUrl = new URL(url)
75+
results.locID = parsedUrl.searchParams.get("id")
76+
// Parse the item out of the page.
77+
const match = page.match(fishCaughtItemRE)
78+
if (!match) {
79+
throw `Unable to find item in fishcaught: ${page}`
80+
}
81+
results.item = match[1]
82+
results.overflow = page.includes("filter: grayscale")
83+
return results
84+
}
85+
86+
const visitFishCaught = async (state, page, url) => {
87+
const results = parseFishCaught(page, url)
88+
const loc = await state.locations.getByID("fishing", results.locID)
89+
if (!loc) {
90+
throw `Unknown fishing loc for results: ${results.locID}`
91+
}
92+
// Update inventory.
93+
state.player.inventory[results.item] = results.overflow ? state.player.maxInventory : ((state.player.inventory[results.item] || 0) + 1)
94+
await state.player.save(state.db)
95+
await state.log.fish({location: loc.name, item: results.item, overflow: results.overflow})
96+
}
97+
6998
export const setupFishing = state => {
7099
state.addPageFilter("https://farmrpg.com/worker.php?go=castnet&id=*", visitNetResults)
71100
state.addPageFilter("https://farmrpg.com/fishing.php?*", visitFishing)
72101
state.addPageFilter("https://farmrpg.com/worker.php?go=sellalluserfish", visitSellAllUserFish)
102+
state.addPageFilter("https://farmrpg.com/worker.php?go=fishcaught&*", visitFishCaught)
73103
}

lib/log.js

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class ActionLog {
3737
return await this.log({type: "cider", results})
3838
}
3939

40+
async fish(results) {
41+
return await this.log({type: "fish", results})
42+
}
43+
4044
async net(results) {
4145
return await this.log({type: "net", results})
4246
}

0 commit comments

Comments
 (0)