let npcNameMap = {} let items = {} class npcObject { constructor(ids, name) { this.ids = ids; this.name = name; this.totalWeight = 0 this.default = [] this.main = [] } } // our json data is out of sync. function itemErrorMessage(npc,item){ console.log("Error with npc",npc," drop id: ",item) console.log("update this tools json/item_config.json") } function newDisplayItem(name, id, min, max, weight, totalWeight) { let row = $("") let icon = $("").attr('src', iconURL(id)) let itemName = $("").text(getItemName(id)) let npcName = $("").text(name) let amount = $("").text((min != max) ? min + "-" + max : min) let debug = $("
").text("id: " + id).addClass(debugClass) let rarity = "" // Weights if (weight != -1) { let percent = (weight / totalWeight) * 100 rarity = $("").text("1/" + (+parseFloat(100 / percent).toFixed(2).replace(/(\.0+|0+)$/, ''))) .prop('title', parseFloat((percent).toFixed(2)) + "%") .attr('data-value', parseFloat((percent).toFixed(2))) .addClass(rarityStyle(percent)) } else { rarity = $("").text("Always").addClass(rarityStyle(100)) .attr('data-value', parseFloat(100)) } return row.append(npcName).append($("").append(icon)).append(itemName.append(debug)).append(amount).append(rarity)[0] } function spaceToUnder(str) { return str.replaceAll(' ', '_').toLowerCase() } function mapNPCItem(drops) { for (const npc of drops) { let name = npcNameMap[npc.ids.split(",")[0]] let npcObj = new npcObject(npc.ids, name) // Add default drops npc['default'].forEach(drop => { if(getItemName(drop.id) == undefined){ itemErrorMessage(npc,drop.id) return } let name = spaceToUnder(getItemName(drop.id)) if (items[name]) items[name] += ("," + npc['ids']) else items[name] = npc['ids'] drop.weight = -1 npcObj.default.push(drop) npcObj[name] = [drop] }) // Normal drops npc['main'].forEach(drop => { if(getItemName(drop.id) == undefined){ itemErrorMessage(npc,drop.id) return } let name = spaceToUnder(getItemName(drop.id)) npcObj.totalWeight += parseFloat(drop.weight) if (items[name]) items[name] += ("," + npc['ids']) else items[name] = npc['ids'] npcObj.main.push(drop) if (npcObj[name]) npcObj[name].push(drop) else npcObj[name] = [drop] }) allNPCs[name] = npcObj } } function mapNPCNames(npcs) { Object.keys(npcs).forEach(npcName => { npcs[npcName].split(",").every(id => npcNameMap[id] = npcName) }) } function search(e) { let input = spaceToUnder(e.value) let table = document.getElementById("dcontent") table.innerHTML = "" Object.keys(items).forEach(itemName => { let itemDisplay = $("") if (input.length > 3 && itemName.includes(input)) { console.log(input + " is like " + itemName) let npcName = "" let npcIDs = items[spaceToUnder(itemName)].split(",") for (const npc of npcIDs) { if (npcNameMap[npc] && npcNameMap[npc] != npcName) { npcName = npcNameMap[npc] if (allNPCs[npcName][itemName]) { // For monsters dropping the same ID in different ways (count) increment index try { for (const item of allNPCs[npcName][itemName]) { itemDisplay.append(newDisplayItem(npcName, item.id, item.minAmount, item.maxAmount, item.weight, allNPCs[npcName].totalWeight)) } } catch (e) { console.log("error in" + e) } } } } if (itemDisplay[0].childElementCount > 0) { let h1 = $("

").addClass("hover-link").append($("
").text(prettyName(itemName))) .on('mouseenter', function () { $(this).text(prettyName(itemName)).append($("").attr('src', ".././img/items/link.png")) }) .on('click', function () { window.location = window.location.toString().split('?')[0] + "?" + this.innerText }) .on('mouseleave', function () { $(this).find($("img")).remove() }) table.appendChild($("
").append(h1) .append($("
") .addClass(debugClass) .append($("

") .text("NPC ids: " + npcIDs)))[0]) itemDisplay.on('click', function (e) { e = e.currentTarget // Classname is used to track the sorting direction let sortOrder = (e.className === 'true'); e.className = 'true' sortByRarity(e, !sortOrder) }) table.append(itemDisplay[0]) } } }); } window.addEventListener('load', () => { let timeout = 0; let checkExist = setInterval(function () { if (allDrops != undefined && allNPCs != undefined && allItems != undefined) { clearInterval(checkExist); mapNPCNames(allNPCs) mapNPCItem(allDrops) searchURLString() } checkTimeout(timeout++) }, 100); });