summaryrefslogtreecommitdiff
path: root/server/frob/itemdb.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/frob/itemdb.ts')
-rw-r--r--server/frob/itemdb.ts68
1 files changed, 68 insertions, 0 deletions
diff --git a/server/frob/itemdb.ts b/server/frob/itemdb.ts
new file mode 100644
index 0000000..5ff943d
--- /dev/null
+++ b/server/frob/itemdb.ts
@@ -0,0 +1,68 @@
+class ItemDB {
+ private item_line =
+ "^" +
+ "(?<id>[0-9]+),[ \t]*" +
+ "(?<name>[^ \t,]+),[ \t]*" +
+ "(?<type>[0-9]+),[ \t]*" +
+ "(?<price>[0-9]+),[ \t]*" +
+ "(?<sell>[0-9]+),[ \t]*" +
+ "(?<weight>[0-9]+),[ \t]*" +
+ "(?<atk>[0-9]+),[ \t]*" +
+ "(?<def>[0-9]+),[ \t]*" +
+ "(?<range>[0-9]+),[ \t]*" +
+ "(?<mbonus>[0-9-]+),[ \t]*" +
+ "(?<slot>[0-9]+),[ \t]*" +
+ "(?<gender>[0-9]+),[ \t]*" +
+ "(?<loc>[0-9]+),[ \t]*" +
+ "(?<wlvl>[0-9]+),[ \t]*" +
+ "(?<elvl>[0-9]+),[ \t]*" +
+ "(?<view>[0-9]+),[ \t]*" +
+ "\{(?<usescript>[^\}]*)\},[ \t]*" +
+ "\{(?<equipscript>[^\}]*)\}[ \t]*" +
+ "$";
+ private item_regex: RegExp;
+
+ constructor () {
+ this.item_regex = new RegExp(this.item_line);
+ }
+
+ private parseLine (line) {
+ const match = this.item_regex.exec(line);
+
+ if (!(match instanceof Object) || !Reflect.has(match, "groups")) {
+ console.error("line does not match the item db regex:", line);
+ throw new SyntaxError();
+ }
+
+ return (match as any).groups;
+ }
+
+ public async * readDB () {
+ const decoder = new TextDecoder("utf-8");
+ console.info("reading tmwa-map.conf...");
+ const file = await Deno.readFile("world/map/conf/tmwa-map.conf");
+ const data = decoder.decode(file).split("\n");
+ const db_regex = new RegExp("^item_db: *(?<path>[A-Za-z0-9_\./]+)$");
+
+ for (const line of data) {
+ const match = db_regex.exec(line);
+ if (!(match instanceof Object)) continue;
+ const path = (match as any).groups.path;
+
+ console.info(`reading world/map/${path}...`)
+ const db = await Deno.readFile(`world/map/${path}`);
+
+ for (const item of decoder.decode(db).split("\n")) {
+ if (item.startsWith("//") || item.length < 2) {
+ continue;
+ }
+
+ yield this.parseLine(item);
+ }
+ }
+ }
+}
+
+export {
+ ItemDB
+}