-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathperfection.ts
More file actions
66 lines (58 loc) · 2.27 KB
/
perfection.ts
File metadata and controls
66 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
export interface PerfectionRet {
numObelisks?: number;
goldenClock?: boolean;
perfectionWaivers?: number;
}
export const parsePerfection = (
SaveGame: any,
): PerfectionRet => {
let numObelisks = 0;
let goldenClock = false;
let perfectionWaivers = 0;
// StardewValley.Utitility.cs::numObelisksOnFarm()
const obelisks = new Set([
"Water Obelisk",
"Earth Obelisk",
"Desert Obelisk",
"Island Obelisk",
]);
try {
perfectionWaivers = SaveGame.perfectionWaivers ?? 0;
// loop through every building looking for obelisks and golden clock
// shared between all players on the farm
// For now, we'll only look in the GameLocation named "Farm", if this is wrong, we'll fix it later
for (const location of SaveGame.locations.GameLocation) {
if (!(Object.entries(location).some(([k, v]) => k.endsWith(':type') && v == 'Farm'))) continue;
if (!location.buildings)
return { numObelisks, goldenClock, perfectionWaivers };
// check to see if there are multiple buildings
if (Array.isArray(location.buildings.Building)) {
for (const building of location.buildings.Building) {
if (obelisks.has(building.buildingType)) {
// check if building is done being built
if (building.daysOfConstructionLeft <= 0) numObelisks++;
} else if (building.buildingType === "Gold Clock") {
// check if building is done being built
if (building.daysOfConstructionLeft <= 0) goldenClock = true;
}
}
} else {
// only one building
const building = location.buildings.Building;
if (obelisks.has(building.buildingType)) {
// check if building is done being built
if (building.daysOfConstructionLeft <= 0) numObelisks++;
} else if (building.buildingType === "Gold Clock") {
// check if building is done being built
if (building.daysOfConstructionLeft <= 0) goldenClock = true;
}
}
return { numObelisks, goldenClock, perfectionWaivers };
}
} catch (err) {
if (err instanceof Error)
throw new Error(`Error in parsePerfection: ${err.message}`);
throw new Error(`Error in parsePerfection: ${err}`);
}
return { numObelisks, goldenClock, perfectionWaivers };
};