-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiscover.ts
156 lines (122 loc) · 4.01 KB
/
discover.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { Results } from "./results";
function isNumeric(value: string) {
return /^-?\d+$/.test(value);
}
function isImage(value: string) {
return value.endsWith(".gif");
}
function isDescid(value: string) {
return /^[a-f0-9]{32}$/.test(value);
}
const EQUIPMENTS = [
"weapon",
"offhand",
"container",
"accessory",
"shirt",
"pants",
"hat",
];
const SECTIONS = [...EQUIPMENTS, "food", "drink", "potion"];
function getSection(types: string[]) {
return types.find((t) => SECTIONS.includes(t)) ?? "misc";
}
const ITEM_CACHE: string[] = [];
function discoverItem(results: Results, discovery: string[]) {
const item = discovery[0].split("\t");
if (ITEM_CACHE.includes(item[0])) return;
ITEM_CACHE.push(item[0]);
results.items.push(discovery[0]);
if (discovery.length === 1) return;
const types = item[4].split(", ");
const section = getSection(types);
if (EQUIPMENTS.includes(section)) {
results.equipment.push({ section, line: discovery[1] });
results.modifiers.push({ section, line: discovery.slice(2) });
return;
}
if (section === "food") {
results.fullness.push(discovery[1]);
results.modifiers.push({ section, line: discovery.slice(2) });
return;
}
if (section === "drink") {
results.inebriety.push(discovery[1]);
results.modifiers.push({ section, line: discovery.slice(2) });
return;
}
if (section && discovery[1] !== `# ${item[1]}`) {
results.modifiers.push({ section, line: discovery.slice(1) });
return;
}
}
function discoverSkill(results: Results, discovery: string[]) {
results.skills.push(discovery[0]);
if (discovery.length === 1) return;
results.modifiers.push({ section: "skill", line: discovery.slice(1) });
}
function discoverEffect(results: Results, discovery: string[]) {
results.effects.push(discovery[0]);
if (discovery.length === 1) return;
results.modifiers.push({ section: "status effect", line: discovery.slice(1) });
}
function discoverOutfit(results: Results, discovery: string[]) {
const id = discovery[0].slice(0, discovery[0].indexOf("\t") + 1);
// Outfit logs are improved over time, so replace instead of push
const idx = results.outfits.findIndex((v) => v.startsWith(id));
results.outfits[idx > -1 ? idx : results.outfits.length] = discovery[0];
if (idx < 0 || discovery.length === 1) return;
results.modifiers.push({ section: "outfit", line: discovery.slice(1) });
}
function discoverShop(results: Results, discovery: string[]) {
results.shop.push(...discovery);
}
export function discoverMonster(
results: Results,
id: number,
name: string,
image: string,
) {
results.monsters.push(`${name}\t${id}\t${image}\t`);
}
export function discoverFamiliar(
results: Results,
id: number,
name: string,
image: string,
hatchling: string,
) {
const equip = "";
const types = "";
results.familiars.push(
`${id}\t${name}\t${image}\t${types}\t${hatchling}\t${equip}\t0\t0\t0\t0`,
);
}
const DISCOVERY_CACHE: string[] = [];
export function discover(results: Results, discovery: string[]) {
if (DISCOVERY_CACHE.includes(discovery.join("\n"))) {
return;
}
DISCOVERY_CACHE.push(discovery.join("\n"));
const last = discovery[discovery.length - 1];
if (last.startsWith("Item\t")) return discoverItem(results, discovery);
if (last.startsWith("Skill\t")) return discoverSkill(results, discovery);
if (last.startsWith("Effect\t")) return discoverEffect(results, discovery);
if (last.startsWith("Outfit\t")) return discoverOutfit(results, discovery);
if (last.match(/\tROW\d+$/)) return discoverShop(results, discovery);
const pieces = discovery[0].split("\t");
if (
(pieces.length === 7 || pieces.length === 8) &&
isNumeric(pieces[2]) &&
isImage(pieces[3])
)
return discoverItem(results, discovery);
if ((pieces.length === 6 || pieces.length === 7) && isImage(pieces[2])) {
if (isDescid(pieces[3])) {
return discoverEffect(results, discovery);
} else {
return discoverSkill(results, discovery);
}
}
console.log("Did not identify", discovery);
}