Melvor drop chance

Adds drop chances to the view drops screen (percentage to 3 significant figures)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Melvor drop chance
// @version      0.1.2
// @description  Adds drop chances to the view drops screen (percentage to 3 significant figures)
// @author       8992
// @match        https://*.melvoridle.com/*
// @grant        none
// @namespace    http://tampermonkey.net/
// @noframes
// ==/UserScript==

let loadCheckInterval = setInterval(() => {
  if (isLoaded) {
    clearInterval(loadCheckInterval);
    loadScript();
  }
}, 200);

function loadScript() {
  window.viewMonsterDrops = (monsterID) => {
    if (monsterID === null) monsterID = combatData.enemy.id;
    if (monsterID >= 0 && MONSTERS[monsterID].lootTable !== undefined) {
      let drops = "";
      let dropsOrdered = [];
      let totalWeight = MONSTERS[monsterID].lootTable.reduce((sum, a) => sum + a[1], 0);
      if (MONSTERS[monsterID].lootChance != undefined) {
        totalWeight = totalWeight * 100 / MONSTERS[monsterID].lootChance;
      }
      for (let i = 0; i < MONSTERS[monsterID].lootTable.length; i++) {
        dropsOrdered.push({
          itemID: MONSTERS[monsterID].lootTable[i][0],
          w: MONSTERS[monsterID].lootTable[i][1],
          qty: MONSTERS[monsterID].lootTable[i][2],
          chance: ` (${(MONSTERS[monsterID].lootTable[i][1] / totalWeight * 100).toPrecision(3)}%)`
        });
      }
      dropsOrdered.sort(function (a, b) {
        return b.w - a.w;
      });
      for (let i = 0; i < dropsOrdered.length; i++) {
        drops +=
          "Up to " +
          dropsOrdered[i].qty +
          ' x <img class="skill-icon-xs mr-2" src="' +
          getItemMedia(dropsOrdered[i].itemID) +
          '">' +
          items[dropsOrdered[i].itemID].name +
          dropsOrdered[i].chance +
          "<br>";
      }
      let bones = "";
      if (MONSTERS[monsterID].bones !== null)
        bones =
          'Always Drops:<br><small><img class="skill-icon-xs mr-2" src="' +
          getItemMedia(MONSTERS[monsterID].bones) +
          '">' +
          items[MONSTERS[monsterID].bones].name +
          "</small><br><br>";
      Swal.fire({
        title: MONSTERS[monsterID].name,
        html:
          bones +
          "Possible Extra Drops:<br><small>In order of most common to least common<br>" +
          drops,
        imageUrl: MONSTERS[monsterID].media,
        imageWidth: 64,
        imageHeight: 64,
        imageAlt: MONSTERS[monsterID].name,
      });
    }
  }

  window.viewItemContents = (itemID = -1) => {
    if (itemID < 0) itemID = selectedBankItem;
    let drops = "";
    let dropsOrdered = [];
    let totalWeight = items[itemID].dropTable.reduce((sum, a) => sum + a[1], 0);
    for (let i = 0; i < items[itemID].dropTable.length; i++) {
      dropsOrdered.push({
        itemID: items[itemID].dropTable[i][0],
        w: items[itemID].dropTable[i][1],
        id: i,
        chance: ` (${(items[itemID].dropTable[i][1] / totalWeight * 100).toPrecision(3)}%)`,
      });
    }
    dropsOrdered.sort(function (a, b) {
      return b.w - a.w;
    });
    for (let i = 0; i < dropsOrdered.length; i++) {
      drops +=
        "Up to " +
        numberWithCommas(items[itemID].dropQty[dropsOrdered[i].id]) +
        ' x <img class="skill-icon-xs mr-2" src="' +
        getItemMedia(dropsOrdered[i].itemID) +
        '">' +
        items[dropsOrdered[i].itemID].name +
        dropsOrdered[i].chance +
        "<br>";
    }
    Swal.fire({
      title: items[itemID].name,
      html: "Possible Items:<br><small>" + drops,
      imageUrl: getItemMedia(itemID),
      imageWidth: 64,
      imageHeight: 64,
      imageAlt: items[itemID].name,
    });
  }
}