From 53280b25ce802e07bd3a639c36dcee847ac8bfbe Mon Sep 17 00:00:00 2001 From: Casey Raethke Date: Tue, 28 Nov 2023 16:01:07 -0600 Subject: [PATCH] Add GenerateBaseArmor --- .gitignore | 11 +- .../GenerateBaseArmor/GenerateBaseArmor.mjs | 150 ++++++++++++++++++ scripts/GenerateBaseArmor/package-lock.json | 21 +++ scripts/GenerateBaseArmor/package.json | 14 ++ 4 files changed, 191 insertions(+), 5 deletions(-) create mode 100755 scripts/GenerateBaseArmor/GenerateBaseArmor.mjs create mode 100644 scripts/GenerateBaseArmor/package-lock.json create mode 100644 scripts/GenerateBaseArmor/package.json diff --git a/.gitignore b/.gitignore index a25ecb1..2e9a626 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -libs/* -!libs/TipHooker-1.0 -!libs/StatLogic -.release -.vscode +libs/* +!libs/TipHooker-1.0 +!libs/StatLogic +.release +.vscode +node_modules diff --git a/scripts/GenerateBaseArmor/GenerateBaseArmor.mjs b/scripts/GenerateBaseArmor/GenerateBaseArmor.mjs new file mode 100755 index 0000000..4f94150 --- /dev/null +++ b/scripts/GenerateBaseArmor/GenerateBaseArmor.mjs @@ -0,0 +1,150 @@ +#!/usr/bin/env node + +import { argv } from 'node:process' +import * as https from 'node:https' +import { parse } from 'csv-parse' +import * as fs from 'node:fs' + +let product = argv[2] +if(!product) { + product = "wow_classic_ptr" + console.log(`Product not specified, using ${product}`) +} + +let rawVersionData = await new Promise((resolve) => { + https.get("https://wago.tools/api/builds", (res) => { + let data = '' + res.on('data', (chunk) => data += chunk) + + res.on('end', () => { + resolve(data) + }) + }) +}) +const versionData = JSON.parse(rawVersionData) +const version = versionData[product][0].version +console.log(`Latest ${product} version: ${version}`) + +// InventoryTypes that can contain a mix of Armor and Bonus Armor +// https://warcraft.wiki.gg/wiki/Enum.InventoryType +const InventoryTypeSlots = { + 1: "HEADSLOT", + 3: "SHOULDERSLOT", + 5: "CHESTSLOT", + 6: "WAISTSLOT", + 7: "LEGSSLOT", + 8: "FEETSLOT", + 9: "WRISTSLOT", + 10: "HANDSSLOT", + 14: "SECONDARYHANDSLOT", + 16: "BACKSLOT", + 20: "CHESTSLOT", +} + +// https://warcraft.wiki.gg/wiki/Enum.ItemQuality +const ItemQualities = { + 0: "Enum.ItemQuality.Poor", + 1: "Enum.ItemQuality.Standard", // in-game doesn't match wiki + 2: "Enum.ItemQuality.Good", // in-game doesn't match wiki + 3: "Enum.ItemQuality.Rare", + 4: "Enum.ItemQuality.Epic", + 5: "Enum.ItemQuality.Legendary", + 6: "Enum.ItemQuality.Artifact", + 7: "Enum.ItemQuality.Heirloom", + 8: "Enum.ItemQuality.WoWToken", +} + +const items = {} +await new Promise((resolve) => { + const csvStream = parse({ + columns: true, + }).on('readable', () => { + let item; + while ((item = csvStream.read()) !== null) { + if(item.QualityModifier > 0 ) { + items[item.ID] = { + Quality: ItemQualities[item.OverallQualityID], + Slot: InventoryTypeSlots[item.InventoryType], + Armor: item.Resistances_0, + ItemLevel: item.ItemLevel + } + } + } + }).on('end', () => { + resolve() + }) + + const filter = Object.keys(InventoryTypeSlots).join("|") + const url = `https://wago.tools/db2/ItemSparse/csv?version=${version}&filter[InventoryType]=${filter}&sort[QualityModifier]=desc` + https.get(url, (res) => { + res.pipe(csvStream) + }) +}) + +console.log("Parsed ItemSparse.db2") + +// https://warcraft.wiki.gg/wiki/ItemType#4:_Armor +const ItemArmorSubclasses = { + 1: "Enum.ItemArmorSubclass.Cloth", + 2: "Enum.ItemArmorSubclass.Leather", + 3: "Enum.ItemArmorSubclass.Mail", + 4: "Enum.ItemArmorSubclass.Plate", + 6: "Enum.ItemArmorSubclass.Shield", +} + +await new Promise((resolve) => { + const csvStream = parse({ + columns: true + }).on('readable', () => { + let item; + while ((item = csvStream.read()) !== null) { + if(items[item.ID]) { + const subclass = ItemArmorSubclasses[item.SubclassID] + if(subclass) { + items[item.ID].SubclassID = subclass + } else { + delete items[item.ID] + } + } + } + }).on('end', () => { + resolve() + }) + + const filter = Object.keys(items).join("|") + const url = `https://wago.tools/db2/Item/csv?version=${version}&filter[ID]=${filter}` + https.get(url, (res) => { + res.pipe(csvStream) + }) +}) + +console.log("Parsed Item.db2") + +const baseArmor = {} +for(const item of Object.values(items)) { + let quality = baseArmor[item.Quality] ||= {} + let slot = quality[item.Slot] ||= {} + let subclass = slot[item.SubclassID] ||= {} + subclass[item.ItemLevel] = item.Armor +} + +let data = "addon.baseArmorTable = {\n" +const indent = "\t" +const generateLua = function(obj, level) { + level ||= 1 + for(const [key, value] of Object.entries(obj)) { + if(typeof(value) === "object") { + data = data.concat(indent.repeat(level), "[", key, "] = {\n") + generateLua(value, level + 1) + data = data.concat(indent.repeat(level), "},\n") + } else { + data = data.concat(indent.repeat(level), "[", key, "] = ", value, ",\n") + } + } +} +generateLua(baseArmor) +data = data + "}\n" + +const filename = `Bonus_Armor_${version}.lua` +fs.writeFileSync(filename, data) +console.log(`Wrote ${filename}`) \ No newline at end of file diff --git a/scripts/GenerateBaseArmor/package-lock.json b/scripts/GenerateBaseArmor/package-lock.json new file mode 100644 index 0000000..fdc779d --- /dev/null +++ b/scripts/GenerateBaseArmor/package-lock.json @@ -0,0 +1,21 @@ +{ + "name": "generatebasearmor", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "generatebasearmor", + "version": "1.0.0", + "license": "GPL-2.0", + "dependencies": { + "csv-parse": "^5.5.2" + } + }, + "node_modules/csv-parse": { + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-5.5.2.tgz", + "integrity": "sha512-YRVtvdtUNXZCMyK5zd5Wty1W6dNTpGKdqQd4EQ8tl/c6KW1aMBB1Kg1ppky5FONKmEqGJ/8WjLlTNLPne4ioVA==" + } + } +} diff --git a/scripts/GenerateBaseArmor/package.json b/scripts/GenerateBaseArmor/package.json new file mode 100644 index 0000000..901e644 --- /dev/null +++ b/scripts/GenerateBaseArmor/package.json @@ -0,0 +1,14 @@ +{ + "name": "generatebasearmor", + "version": "1.0.0", + "description": "", + "main": "GenerateBaseArmor.mjs", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "GPL-2.0", + "dependencies": { + "csv-parse": "^5.5.2" + } +}