From f58c4c09f760183c1d86bb138f1641d7b7a28775 Mon Sep 17 00:00:00 2001 From: downthecrop Date: Wed, 20 Sep 2023 08:00:45 -0700 Subject: [PATCH] Drop Table Tool - Charm Drops (#236) * remove pastes (was for manual static html creation) * Basics of adding charms into the drop table tool * Charms + Break Vue into component files --- .../VSCODE - Menu Box Find + Replace Regex | 13 - 2009pastes/menubox.html | 61 --- 2009pastes/menuboxChangerScript.js | 23 - 2009pastes/newsitemMenu.html | 10 - services/m=data/LICENSE | 7 - services/m=data/css/style.css | 11 + services/m=data/drop-table/index.html | 8 +- services/m=data/js/DataStructures.js | 58 +++ services/m=data/js/components/ItemData.js | 96 +++++ services/m=data/js/components/ItemSources.js | 27 ++ services/m=data/js/components/NPCDrops.js | 46 ++ services/m=data/js/components/Navbar.js | 30 ++ services/m=data/js/searchtool.js | 237 +++++++++++ services/m=data/searchtool.js | 400 ------------------ 14 files changed, 507 insertions(+), 520 deletions(-) delete mode 100644 2009pastes/VSCODE - Menu Box Find + Replace Regex delete mode 100644 2009pastes/menubox.html delete mode 100644 2009pastes/menuboxChangerScript.js delete mode 100644 2009pastes/newsitemMenu.html delete mode 100644 services/m=data/LICENSE create mode 100644 services/m=data/js/DataStructures.js create mode 100644 services/m=data/js/components/ItemData.js create mode 100644 services/m=data/js/components/ItemSources.js create mode 100644 services/m=data/js/components/NPCDrops.js create mode 100644 services/m=data/js/components/Navbar.js create mode 100644 services/m=data/js/searchtool.js delete mode 100644 services/m=data/searchtool.js diff --git a/2009pastes/VSCODE - Menu Box Find + Replace Regex b/2009pastes/VSCODE - Menu Box Find + Replace Regex deleted file mode 100644 index 2f2dbaeeb..000000000 --- a/2009pastes/VSCODE - Menu Box Find + Replace Regex +++ /dev/null @@ -1,13 +0,0 @@ -Find: -
  • [/&"=.0-9'A-z<>\s\n]*[/&"=.0-9'A-z<>\s\n]*
  • [/&"=.0-9'A-z<>\s\n]*Community - -
  • - -
  • - -
    - \ No newline at end of file diff --git a/2009pastes/menuboxChangerScript.js b/2009pastes/menuboxChangerScript.js deleted file mode 100644 index 244535cf1..000000000 --- a/2009pastes/menuboxChangerScript.js +++ /dev/null @@ -1,23 +0,0 @@ -/* - HOW TO USE THIS SCRIPT: - - Step 1: Put the script where you need it - Step 2: Set "replaceMenuBox" string to the right path (find and replace the number of ./../../'s) - Step 3: Make sure the files are being read from the right path based on the function below - - Always use git. You will mess up your work first try. -*/ - -let fs = require('fs'); -const dir = __dirname + '/m=news/' -files = fs.readdirSync(dir); - -let replaceMenubox = `
    ` - -files.forEach(function (fileName) { - if (fs.lstatSync(dir + fileName).isFile()) { - let contents = fs.readFileSync(dir + fileName, 'utf8'); - const regex = /
    [\s\S]*?<\/div>/i; - fs.writeFileSync(dir + fileName, contents.replace(regex, replaceMenubox)); - } -}) \ No newline at end of file diff --git a/2009pastes/newsitemMenu.html b/2009pastes/newsitemMenu.html deleted file mode 100644 index eec6440d6..000000000 --- a/2009pastes/newsitemMenu.html +++ /dev/null @@ -1,10 +0,0 @@ - \ No newline at end of file diff --git a/services/m=data/LICENSE b/services/m=data/LICENSE deleted file mode 100644 index af702f086..000000000 --- a/services/m=data/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright 2021 downthecrop - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/services/m=data/css/style.css b/services/m=data/css/style.css index 44a4519fb..ea5c493e2 100644 --- a/services/m=data/css/style.css +++ b/services/m=data/css/style.css @@ -12,6 +12,17 @@ body { overflow: hidden; } +.quantity { + font-size:12px; + margin: 0; +} + +.charm-spacer { + height:10px; + text-align:center; + border: none; +} + .stat-data { background-color: #605443; color: white; diff --git a/services/m=data/drop-table/index.html b/services/m=data/drop-table/index.html index 5f13d382e..6debf8a14 100644 --- a/services/m=data/drop-table/index.html +++ b/services/m=data/drop-table/index.html @@ -25,13 +25,9 @@ layout: guide
    -
    - + +
    diff --git a/services/m=data/js/DataStructures.js b/services/m=data/js/DataStructures.js new file mode 100644 index 000000000..f3d71b4d9 --- /dev/null +++ b/services/m=data/js/DataStructures.js @@ -0,0 +1,58 @@ +export class Result { + constructor(name, ids) { + this.name = name; + this.ids = ids; + this.charms = []; + this.items = []; + } +} + +export class NPCObject { + constructor(ids, name) { + this.ids = ids; + this.name = name; + this.totalWeight = 0 + this.totalCharmWeight = 0 + this.default = [] + this.main = [] + this.charm = [] + } +} + +export class DisplayItem { + constructor(id, name, min, max, weight, totalWeight) { + this.percent = (weight / totalWeight) * 100; + this.id = parseInt(id); + this.name = name; + this.minAmount = parseInt(min); + this.maxAmount = parseInt(max); + this.amount = (min != max) ? min + "-" + max : min; + this.weight = weight; + this.totalWeight = totalWeight; + this.fractional = this.getFractional(); + this.rarity = (this.weight != -1) ? parseFloat((this.percent).toFixed(2)) : 100; + this.rarityStyle = this.getStyle(); + this.expectedQuantity = this.getExpectedQuantity(); + } + + getStyle() { + if (this.rarity > 99.99) return "always" + if (this.rarity > 4) return "common" + if (this.rarity > 1) return "uncommon" + if (this.rarity > 0.1) return "rare" + return "veryrare" + } + getFractional() { + if (this.weight === -1) return "Always" + return "1/" + (+parseFloat(100 / this.percent).toFixed(2).replace(/(\.0+|0+)$/, '')) + } + getExpectedQuantity() { + let t = 0; + if (this.minAmount > this.maxAmount) { + console.error("ERROR WITH DROP ID", this.id, "- MinValue > MaxValue") + return (0) + } + const range = Array(this.maxAmount - this.minAmount + 1).fill(1).map((x, y) => this.minAmount + y); + return ((range.reduce((a, b) => a + b, t) / range.length * (this.rarity / 100))).toFixed(2) + } +} \ No newline at end of file diff --git a/services/m=data/js/components/ItemData.js b/services/m=data/js/components/ItemData.js new file mode 100644 index 000000000..febe22f53 --- /dev/null +++ b/services/m=data/js/components/ItemData.js @@ -0,0 +1,96 @@ +export default Vue.defineComponent({ + template: + ` +
    +

    {{ item.name }}

    +

    Item id: {{ item.id }}

    + + + +
    Attack bonuses
    + + + + + + + + + {{bonus.aStab}} + {{bonus.aSlash}} + {{bonus.aCrush}} + {{bonus.aMagic}} + {{bonus.aRanged}} + + +
    Defense bonuses
    + + + + + + + + + + {{bonus.dStab}} + {{bonus.dSlash}} + {{bonus.dCrush}} + {{bonus.dMagic}} + {{bonus.dRanged}} + {{bonus.dSummoning}} + + +
    Other bonuses
    + + + + + + + + {{bonus.strength}} + {{bonus.rangedStr}} + {{bonus.magicStr}} + {{bonus.prayer}} + + + + {{item.name}} + +

    {{prop.key}} {{prop.val}}

    + + + +
    + `, + methods: { + getBonuses(item) { + const stats = item.bonuses.split(",") + return { + aStab: stats[0], + aSlash: stats[1], + aCrush: stats[2], + aMagic: stats[3], + aRanged: stats[4], + dStab: stats[5], + dSlash: stats[6], + dCrush: stats[7], + dMagic: stats[8], + dRanged: stats[9], + dSummoning: stats[10], + strength: stats[11], + prayer: stats[12], + magicStr: stats[13], + rangedStr: stats[14], + } + }, + dumpKeys(item) { + return Object.entries(item).map(([key, val]) => ({ key, val })) + } + }, + props: { + searchResults: { type: Object }, + iconURL: { type: Function }, + } +}); \ No newline at end of file diff --git a/services/m=data/js/components/ItemSources.js b/services/m=data/js/components/ItemSources.js new file mode 100644 index 000000000..5b73aecee --- /dev/null +++ b/services/m=data/js/components/ItemSources.js @@ -0,0 +1,27 @@ +export default Vue.defineComponent({ + template: + ` +
    +

    {{ item.name }}

    +

    NPC ids: {{ item.ids }}

    + + + {{npc.name}} + + {{item.name}}
    id: {{npc.id}} + + {{npc.amount}} +
    +

    {{npc.expectedQuantity}}

    + + {{npc.fractional}} + + +
    + `, + props: { + searchResults: { type: Object }, + sortItems: { type: Function }, + iconURL: { type: Function }, + } +}); \ No newline at end of file diff --git a/services/m=data/js/components/NPCDrops.js b/services/m=data/js/components/NPCDrops.js new file mode 100644 index 000000000..d92f64bb6 --- /dev/null +++ b/services/m=data/js/components/NPCDrops.js @@ -0,0 +1,46 @@ +export default Vue.defineComponent({ + template: + ` +
    +

    {{ npc.name }}

    +

    NPC ids: {{ npc.ids }}

    + + + + {{item.name}}
    id: {{item.id}} + + {{item.amount}} +
    +

    + {{item.expectedQuantity}} +

    + + {{item.fractional}} + + + + + + + + + + {{item.name}}
    id: {{item.id}} + + {{item.amount}} +
    +

    + {{item.expectedQuantity}} +

    + + {{item.fractional}} + + +
    + `, + props: { + searchResults: { type: Object }, + sortItems: { type: Function }, + iconURL: { type: Function }, + } +}); \ No newline at end of file diff --git a/services/m=data/js/components/Navbar.js b/services/m=data/js/components/Navbar.js new file mode 100644 index 000000000..8d6170f7e --- /dev/null +++ b/services/m=data/js/components/Navbar.js @@ -0,0 +1,30 @@ + + +export default Vue.defineComponent({ + template: + ` +
    + Drop Tables + Item Sources + Item Data +
    +
    + {{pick}} +
    +
    + +

    Notes: RDT Slot = Rare Drop Table (link), Summoning Charms are rolled separately

    +
    +
    + `, + data() { + return { + pick: "Drop Tables", + input: "", + } + }, + methods: { + updatePick() { this.$emit('update-pick', this.pick) }, + updateInput() { this.$emit('update-input', this.input) } + } +}); \ No newline at end of file diff --git a/services/m=data/js/searchtool.js b/services/m=data/js/searchtool.js new file mode 100644 index 000000000..5988a0b6c --- /dev/null +++ b/services/m=data/js/searchtool.js @@ -0,0 +1,237 @@ +import { Result, DisplayItem, NPCObject } from './DataStructures.js'; +import Navbar from './components/Navbar.js'; +import NPCDrops from './components/NPCDrops.js'; +import ItemData from './components/ItemData.js'; +import ItemSources from './components/ItemSources.js'; + +Vue.createApp({ + template: ` +
    + + + + + + + + + + + + +
    + +
    +

    Loading JSON..

    +
    + `, + components: { + Navbar, + NPCDrops, + ItemData, + ItemSources + }, + data() { + return { + dropTables: null, + itemConfigs: null, + itemIdToName: {}, + npcObjects: {}, + npcIdToName: {}, + itemSourceNPCIds: {}, + input: "", + pick: "Drop Tables", + searchResults: [], + } + }, + methods: { + updateParentPick(newPick) { + this.pick = newPick; + }, + updateParentInput(newInput) { + this.input = newInput; + }, + iconURL(id) { + switch (id) { + case 0: return "../img/items/nothing.webp"; + case 1: return "../img/items/2677.webp"; //Clue Scroll (easy) + case 5733: return "../img/items/2801.webp"; //Clue Scroll (medium) + case 12070: return "../img/items/2722.webp"; //Clue Scroll (hard) + default: return "../img/items/" + id + ".webp" + } + }, + sortItems(d, key) { + d[`${key}Sorted`] = !d[`${key}Sorted`]; + d.items.sort((a, b) => d[`${key}Sorted`] ? a[key] - b[key] : b[key] - a[key]); + }, + spaceToUnder(str) { + return str.replaceAll(' ', '_').toLowerCase() + }, + isNormalCharm(id) { + const charms = ["12163", "12160", "12159", "12158"] + return charms.includes(id) + }, + search(input) { + this.searchResults = [] + + const pushItemsToResult = (drops, result, propName, totalWeight) => { + for (const drop of drops) { + result[propName].push(new DisplayItem( + drop.id, drop.name, drop.minAmount, drop.maxAmount, + drop.weight, + totalWeight + )); + } + }; + + if (input.length > 2) { + const searchTerm = this.spaceToUnder(input) + if (this.pick == "Item Sources") { + Object.keys(this.itemSourceNPCIds).forEach(itemName => { + if (!itemName.includes(searchTerm)) return; + + const npcIds = this.itemSourceNPCIds[this.spaceToUnder(itemName)]; + const result = new Result(null, npcIds); + let npcName = ""; + + for (const id of npcIds.split(",")) { + const newNpcName = this.npcIdToName[id]; + if (newNpcName && newNpcName !== npcName) { + npcName = newNpcName; + const npcObj = this.npcObjects[npcName]; + if (!npcObj) continue; + + for (const item of npcObj[itemName] || []) { + result.name = result.name || item.name; + const totalWeight = this.isNormalCharm(item.id) ? npcObj.totalCharmWeight : npcObj.totalWeight; + result.items.push(new DisplayItem(item.id, npcName, item.minAmount, item.maxAmount, item.weight, totalWeight)); + } + } + } + this.searchResults.push(result); + }); + + } else if (this.pick == "Drop Tables") { + // bynpc.js + Object.keys(this.npcObjects).forEach(npcName => { + const npcObj = this.npcObjects[npcName]; + if (this.spaceToUnder(npcName).includes(searchTerm)) { + const result = new Result(npcName, npcObj.ids); + pushItemsToResult(npcObj.default, result, 'items', -1); + pushItemsToResult(npcObj.main, result, 'items', npcObj.totalWeight); + pushItemsToResult(npcObj.charm, result, 'charms', npcObj.totalCharmWeight); + this.searchResults.push(result); + } + }); + } else if (this.pick == "Item Data") { + // itemdata.js + for (const item of this.itemConfigs) { + if (this.spaceToUnder(item.name).includes(searchTerm)) { + console.log(searchTerm + " is like itemData: " + item.name) + this.searchResults.push(item) + } + } + } + } + } + }, + watch: { + input() { this.search(this.input) }, + pick() { this.search(this.input) } + }, + created() { + // Proxy is used because GitLAB has CORS restrictions while GitHUB doesn't. + // this is refreshed every 15 minutes. If it's out of sync ping @downthecrop + const PROXY = "https://downthecrop.github.io/2009scape-mirror/Server/data/configs/"; + + const fetchData = async (url) => { + const response = await fetch(PROXY + url); + return await response.json(); + }; + + const initConfigs = async () => { + const [npcConfigs, dropTables, itemConfigs] = await Promise.all([ + fetchData("npc_configs.json"), + fetchData("drop_tables.json"), + fetchData("item_configs.json") + ]); + + this.npcIdToName = Object.fromEntries(npcConfigs.map(npc => [npc.id, npc.name])); + this.itemIdToName = Object.fromEntries(itemConfigs.map(item => [item.id, item.name])); + this.dropTables = dropTables; + this.itemConfigs = itemConfigs; + + // Edge cases + this.itemIdToName["0"] = "Nothing"; + this.itemIdToName["12070"] = "Clue Scroll (hard)"; + this.itemIdToName["5733"] = "Clue Scroll (medium)"; + this.itemIdToName["1"] = "Clue Scroll (easy)"; + }; + + initConfigs(); + + let checkInterval = setInterval(() => { + if (this.itemConfigs && this.dropTables) { + clearInterval(checkInterval); + + const processDrop = (drop, dropType, npcObj) => { + let itemName = this.spaceToUnder(this.itemIdToName[drop.id]); + + if (dropType === 'main') { + npcObj.totalWeight += parseFloat(drop.weight); + } else if (dropType === 'charm') { + npcObj.totalCharmWeight += parseFloat(drop.weight); + } + + if (this.itemSourceNPCIds[itemName]) { + this.itemSourceNPCIds[itemName] += `,${npcObj.ids}`; + } else { + this.itemSourceNPCIds[itemName] = npcObj.ids; + } + + drop.name = this.itemIdToName[drop.id]; + npcObj[dropType].push(drop); + + if (npcObj[itemName]) { + npcObj[itemName].push(drop); + } else { + npcObj[itemName] = [drop]; + } + }; + + for (const npc of this.dropTables) { + let npcName = this.npcIdToName[npc.ids.split(",")[0]]; + if (npcName === undefined) continue; + let npcObj = new NPCObject(npc.ids, npcName); + + if (this.npcObjects[npcName]) { + console.log("Duplicate NPC:", npcName, " id: ", npc.ids); + npcName = npcName + npc.ids.split(",")[0]; + } + + // Add Guaranteed / default drops + npc['default'].forEach(drop => { + drop.weight = -1; + processDrop(drop, 'default', npcObj); + }); + + // Add Normal / main drops + npc['main'].forEach(drop => { + processDrop(drop, 'main', npcObj); + }); + + // Add Charms / charm drops + npc['charm'].forEach(drop => { + processDrop(drop, 'charm', npcObj); + }); + + this.npcObjects[npcName] = npcObj; + } + } + }, 100); + } +}).mount('#app') \ No newline at end of file diff --git a/services/m=data/searchtool.js b/services/m=data/searchtool.js deleted file mode 100644 index 2edd06843..000000000 --- a/services/m=data/searchtool.js +++ /dev/null @@ -1,400 +0,0 @@ -export default { - template: ` -
    -
    - Drop Tables - Item Sources - Item Data -
    -
    - {{pick}} -
    -
    - -

    Notes: RDT Slot = Rare Drop Table (link), Summoning Charms are rolled separately

    -
    -
    - -
    -
    -

    {{ npc.name }}

    -

    NPC ids: {{ npc.ids }}

    - - - - {{item.name}}
    id: {{item.id}} - - {{item.amount}} -
    -

    - {{item.expectedQuantity}} -

    - - {{item.fractional}} - - -
    -
    -
    - -
    -

    {{ item.name }}

    -

    NPC ids: {{ item.ids }}

    - - - {{npc.name}} - - {{item.name}}
    id: {{npc.id}} - - {{npc.amount}} -
    -

    - {{npc.expectedQuantity}} -

    - - {{npc.fractional}} - - -
    -
    -
    - -
    -

    {{ item.name }}

    -

    Item id: {{ item.id }}

    - - - -
    Attack bonuses
    - - - - - - - - - {{bonus.aStab}} - {{bonus.aSlash}} - {{bonus.aCrush}} - {{bonus.aMagic}} - {{bonus.aRanged}} - - -
    Defense bonuses
    - - - - - - - - - - {{bonus.dStab}} - {{bonus.dSlash}} - {{bonus.dCrush}} - {{bonus.dMagic}} - {{bonus.dRanged}} - {{bonus.dSummoning}} - - -
    Other bonuses
    - - - - - - - - {{bonus.strength}} - {{bonus.rangedStr}} - {{bonus.magicStr}} - {{bonus.prayer}} - - - - {{item.name}} - -

    {{prop.key}} {{prop.val}}

    - - - -
    -
    -
    -
    -
    -

    Loading JSON..

    -
    -
    - `, - data() { - return { - dropTables: null, - itemConfigs: null, - itemIdToName: {}, - npcObjects: {}, - npcIdToName: {}, - itemSourceNPCIds: {}, - input: "", - pick: "Drop Tables", - searchResults: [], - } - }, - methods: { - dumpKeys(item) { - const list = [] - for (const [key, value] of Object.entries(item)) { - list.push({ key: key, val: value }) - } - return list - }, - getBonuses(item) { - const stats = item.bonuses.split(",") - return { - aStab: stats[0], - aSlash: stats[1], - aCrush: stats[2], - aMagic: stats[3], - aRanged: stats[4], - dStab: stats[5], - dSlash: stats[6], - dCrush: stats[7], - dMagic: stats[8], - dRanged: stats[9], - dSummoning: stats[10], - strength: stats[11], - prayer: stats[12], - magicStr: stats[13], - rangedStr: stats[14], - } - }, - iconURL(id) { - switch (id) { - case 0: return "../img/items/nothing.webp"; - case 1: return "../img/items/2677.webp"; //Clue Scroll (easy) - case 5733: return "../img/items/2801.webp"; //Clue Scroll (medium) - case 12070: return "../img/items/2722.webp"; //Clue Scroll (hard) - default: return "../img/items/" + id + ".webp" - } - }, - sortFractional(d) { - d.fractionSorted = !d.fractionSorted - if (d.fractionSorted) d.items.sort((a, b) => a.rarity - b.rarity); - else d.items.sort((a, b) => b.rarity - a.rarity); - }, - sortAmount(d) { - d.amountSorted = !d.amountSorted - if (!d.amountSorted) d.items.sort((a, b) => a.maxAmount - b.maxAmount); - else d.items.sort((a, b) => b.maxAmount - a.maxAmount); - }, - spaceToUnder(str) { - return str.replaceAll(' ', '_').toLowerCase() - }, - search(input) { - this.searchResults = [] - - class Result { - constructor(name, ids) { - this.name = name; - this.ids = ids; - this.items = []; - } - } - - class DisplayItem { - constructor(id, name, min, max, weight, totalWeight) { - this.percent = (weight / totalWeight) * 100; - this.id = parseInt(id); - this.name = name; - this.minAmount = parseInt(min); - this.maxAmount = parseInt(max); - this.amount = (min != max) ? min + "-" + max : min; - this.weight = weight; - this.totalWeight = totalWeight; - this.fractional = this.getFractional(); - this.rarity = (this.weight != -1) ? parseFloat((this.percent).toFixed(2)) : 100; - this.rarityStyle = this.getStyle(); - this.expectedQuantity = this.getExpectedQuantity(); - } - getStyle() { - if (this.rarity > 99.99) return "always" - if (this.rarity > 4) return "common" - if (this.rarity > 1) return "uncommon" - if (this.rarity > 0.1) return "rare" - return "veryrare" - } - getFractional() { - if (this.weight === -1) return "Always" - return "1/" + (+parseFloat(100 / this.percent).toFixed(2).replace(/(\.0+|0+)$/, '')) - } - getExpectedQuantity() { - let t = 0; - if(this.minAmount > this.maxAmount ) { - console.error("ERROR WITH DROP ID", this.id, "- MinValue > MaxValue") - return(0) - } - const range = Array(this.maxAmount - this.minAmount + 1).fill(1).map((x, y) => this.minAmount + y); - return ((range.reduce((a, b) => a + b, t) / range.length * (this.rarity / 100))).toFixed(2) - } - } - - if (input.length > 2) { - const searchTerm = this.spaceToUnder(input) - if (this.pick == "Item Sources") { - // byitem.js - Object.keys(this.itemSourceNPCIds).forEach(itemName => { - if (itemName.includes(searchTerm)) { - console.log(searchTerm + " is like item: " + itemName) - - let npcName = "" - let npcIds = this.itemSourceNPCIds[this.spaceToUnder(itemName)] - - const result = new Result(null, npcIds) - - for (const id of npcIds.split(",")) { - if (this.npcIdToName[id] && this.npcIdToName[id] != npcName) { - npcName = this.npcIdToName[id] - if (this.npcObjects[npcName]) { - try { - for (const item of this.npcObjects[npcName][itemName]) { - if (result.name == null) result.name = item.name - result.items.push(new DisplayItem(item.id, npcName, item.minAmount, item.maxAmount, item.weight, this.npcObjects[npcName].totalWeight)) - } - } catch (e) { - console.log("error in" + e) - } - } - } - } - this.searchResults.push(result) - } - }) - } else if (this.pick == "Drop Tables") { - // bynpc.js - Object.keys(this.npcObjects).forEach(npcName => { - if (this.spaceToUnder(npcName).includes(searchTerm)) { - console.log(searchTerm + " is like npc: " + npcName) - const result = new Result(npcName, this.npcObjects[npcName].ids) - // Guaranteed / 'default' drops - for (const drop of this.npcObjects[npcName].default) { - result.items.push(new DisplayItem(drop.id, drop.name, drop.minAmount, drop.maxAmount, -1, -1)) - } - // Normal / 'main' drops - for (const drop of this.npcObjects[npcName].main) { - result.items.push(new DisplayItem(drop.id, drop.name, drop.minAmount, drop.maxAmount, drop.weight, this.npcObjects[npcName].totalWeight)) - } - this.searchResults.push(result) - } - }) - } else if (this.pick == "Item Data") { - // itemdata.js - for (const item of this.itemConfigs) { - if (this.spaceToUnder(item.name).includes(searchTerm)) { - console.log(searchTerm + " is like itemData: " + item.name) - this.searchResults.push(item) - } - } - } - } - } - }, - watch: { - input() { this.search(this.input) }, - pick() { this.search(this.input) } - }, - created() { - // Proxy is used because GitLAB has CORS restrictions while GitHUB doesn't. - // this is refreshed every 15 minutes. If it's out of sync ping @downthecrop - const PROXY = "https://downthecrop.github.io/2009scape-mirror/Server/data/configs/" - fetch(PROXY + "npc_configs.json").then(r => r.json()).then(npc_configs => { - for (const npc of npc_configs) { - this.npcIdToName[npc.id] = npc.name; - } - }); - fetch(PROXY + "drop_tables.json").then(r => r.json()).then(drop_tables => this.dropTables = drop_tables); - fetch(PROXY + "item_configs.json").then(r => r.json()).then(item_configs => { - // Create a dictionary of item ids to item names - for (const item of item_configs) { - this.itemIdToName[item.id] = item.name - } - // Edge cases where an itemId is being used outside of its original name. - // eg 5733 is "Rotten potato" but is instead a medium clue. - this.itemIdToName["0"] = "Nothing" - this.itemIdToName["12070"] = "Clue Scroll (hard)" - this.itemIdToName["5733"] = "Clue Scroll (medium)" - this.itemIdToName["1"] = "Clue Scroll (easy)" - this.itemConfigs = item_configs; - }) - let checkInterval = setInterval(() => { - if (this.itemConfigs && this.dropTables) { - clearInterval(checkInterval); - - // Create an NPC object for each npc in the droptable - class NPCObject { - constructor(ids, name) { - this.ids = ids; - this.name = name; - this.totalWeight = 0 - this.default = [] - this.main = [] - } - } - - for (const npc of this.dropTables) { - let npcName = this.npcIdToName[npc.ids.split(",")[0]] - if (npcName === undefined) continue; - let npcObj = new NPCObject(npc.ids, npcName) - - if (this.npcObjects[npcName]) { - console.log("Duplicate NPC:", npcName, " id: ", npc.ids) - npcName = npcName + npc.ids.split(",")[0] - } - - // Add Guaranteed / default drops - npc['default'].forEach(drop => { - let itemName = this.spaceToUnder(this.itemIdToName[drop.id]) - if (this.itemSourceNPCIds[itemName]) { - // Add the ids of the current NPC to item sourcelist of this drop - this.itemSourceNPCIds[itemName] += `,${npc['ids']}` - } else { - // This is the first NPC dropping this item. - this.itemSourceNPCIds[itemName] = npc['ids'] - } - drop.weight = -1 - drop.name = this.itemIdToName[drop.id] - npcObj.default.push(drop) - if (npcObj[itemName]) { - npcObj[itemName].push(drop) - } else { - npcObj[itemName] = [drop] - } - }) - - // Add Normal / main drops - npc['main'].forEach(drop => { - let itemName = this.spaceToUnder(this.itemIdToName[drop.id]) - npcObj.totalWeight += parseFloat(drop.weight) - if (this.itemSourceNPCIds[itemName]) { - // Add the ids of the current NPC to item sourcelist of this drop - this.itemSourceNPCIds[itemName] += `,${npc['ids']}` - } - else { - // This is the first NPC dropping this item. - this.itemSourceNPCIds[itemName] = npc['ids'] - } - drop.name = this.itemIdToName[drop.id] - npcObj.main.push(drop) - if (npcObj[itemName]) { - npcObj[itemName].push(drop) - } else { - npcObj[itemName] = [drop] - } - }) - this.npcObjects[npcName] = npcObj - } - } - }, 100) - } -} \ No newline at end of file