Melvor Snippets

Collection of various snippets

当前为 2022-03-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Melvor Snippets
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.14
  5. // @description Collection of various snippets
  6. // @grant none
  7. // @author GMiclotte
  8. // @include https://melvoridle.com/*
  9. // @include https://*.melvoridle.com/*
  10. // @exclude https://melvoridle.com/index.php
  11. // @exclude https://*.melvoridle.com/index.php
  12. // @exclude https://wiki.melvoridle.com/*
  13. // @exclude https://*.wiki.melvoridle.com/*
  14. // @inject-into page
  15. // @noframes
  16. // @grant none
  17. // ==/UserScript==
  18.  
  19. ((main) => {
  20. const script = document.createElement('script');
  21. script.textContent = `try { (${main})(); } catch (e) { console.log(e); }`;
  22. document.body.appendChild(script).parentNode.removeChild(script);
  23. })(() => {
  24.  
  25. function startSnippets() {
  26.  
  27. const snippet = {
  28. name: '',
  29. log: (...args) => console.log('Snippets:', ...args),
  30. start: () => snippet.log(`Loading ${snippet.name}.`),
  31. end: () => snippet.log(`Loaded ${snippet.name}.`),
  32. };
  33.  
  34. // header end
  35.  
  36. /////////////////////////////////////
  37. //AgilityObstacleBuildsRemaining.js//
  38. /////////////////////////////////////
  39. snippet.name = 'AgilityObstacleBuildsRemaining.js';
  40. snippet.start();
  41. // show agility obstacles that have been built less than 10 times
  42. listObstaclesWithFewerThanTenBuilds = () => {
  43. agilityObstacleBuildCount.map((_, i) => i)
  44. .filter(i => agilityObstacleBuildCount[i] < 10)
  45. .map(i => agilityObstacles[i])
  46. .map(x => [x.category + 1, x.name]);
  47. }
  48. snippet.end();
  49.  
  50. //////////////////
  51. //DefensePure.js//
  52. //////////////////
  53. snippet.name = 'DefensePure.js';
  54. snippet.start();
  55. // Various Defense Pure Calculations
  56. window.defensePure = {};
  57.  
  58. defensePure.defLvlToHPLvl = def => {
  59. const hpXP = exp.level_to_xp(10) + 1;
  60. const minDefXP = exp.level_to_xp(def) + 1;
  61. const maxDefXP = exp.level_to_xp(def + 1);
  62. const minHpXP = hpXP + minDefXP / 3;
  63. const maxHpXP = hpXP + maxDefXP / 3;
  64. const minHp = exp.xp_to_level(minHpXP) - 1;
  65. const maxHp = exp.xp_to_level(maxHpXP) - 1;
  66. return {min: minHp, max: maxHp};
  67. }
  68.  
  69. defensePure.defLvlToCbLvl = def => {
  70. const hp = defensePure.defLvlToHPLvl(def);
  71. const att = 1, str = 1, ran = 1, mag = 1, pray = 1;
  72. const minBase = (def + hp.min + Math.floor(pray / 2)) / 4;
  73. const maxBase = (def + hp.max + Math.floor(pray / 2)) / 4;
  74. const melee = (att + str) * 1.3 / 8;
  75. const ranged = Math.floor(1.5 * ran) * 1.3 / 8;
  76. const magic = Math.floor(1.5 * mag) * 1.3 / 8;
  77. const best = Math.max(melee, ranged, magic);
  78. return {min: minBase + best, max: maxBase + best};
  79. }
  80.  
  81. defensePure.lastHitOnly = (skillID, maxLevel = 1) => {
  82. if (skillXP[skillID] >= exp.level_to_xp(maxLevel + 1) - 1) {
  83. combatManager.stopCombat();
  84. return;
  85. }
  86. // swap weapon based on hp left
  87. let itemID;
  88. if (combatManager.enemy.hitpoints > 1) {
  89. if (skillID === Skills.Magic) {
  90. itemID = Items.Normal_Shortbow;
  91. } else {
  92. // melee or ranged
  93. itemID = Items.Staff_of_Air;
  94. }
  95. } else {
  96. if (skillID === Skills.Ranged) {
  97. itemID = Items.Iron_Throwing_Knife;
  98. } else if (skillID === Skills.Magic) {
  99. itemID = Items.Staff_of_Air;
  100. } else {
  101. // melee
  102. itemID = -1;
  103. }
  104. }
  105. if (player.equipment.slots.Weapon.item.id !== itemID) {
  106. if (itemID === -1) {
  107. player.unequipItem(0, 'Weapon');
  108. } else {
  109. player.equipItem(itemID, 0);
  110. }
  111. }
  112. // loop
  113. setTimeout(() => defensePure.lastHitOnly(skillID, maxLevel), 1000);
  114. }
  115. snippet.end();
  116.  
  117. /////////////////////////
  118. //GetLocalisationKey.js//
  119. /////////////////////////
  120. snippet.name = 'GetLocalisationKey.js';
  121. snippet.start();
  122. // Get Localisation Key for a given string
  123. getLocalisationKey = (text) => {
  124. const list = []
  125. for (const key in loadedLangJson) {
  126. for (const identifier in loadedLangJson[key]) {
  127. if (loadedLangJson[key][identifier] === text) {
  128. list.push({key: key, identifier: identifier});
  129. }
  130. }
  131. }
  132. return list;
  133. }
  134. snippet.end();
  135.  
  136. //////////////////////
  137. //ListRaidUnlocks.js//
  138. //////////////////////
  139. snippet.name = 'ListRaidUnlocks.js';
  140. snippet.start();
  141. // list unlocked raid items
  142. listCrateItems = (unlocked = true) =>
  143. RaidManager.crateItemWeights.filter(x =>
  144. unlocked === game.golbinRaid.ownedCrateItems.has(x.itemID)
  145. ).forEach(x =>
  146. console.log(items[x.itemID].name)
  147. );
  148. // to list the ones you have unlocked:
  149. // listCrateItems()
  150. // to list the ones you haven't unlocked:
  151. // listCrateItems(false)
  152. snippet.end();
  153.  
  154. //////////////////
  155. //MasteryBars.js//
  156. //////////////////
  157. snippet.name = 'MasteryBars.js';
  158. snippet.start();
  159. // Add Mastery Bars
  160. setInterval(() => {
  161. for (const id in SKILLS) {
  162. if (SKILLS[id].hasMastery) {
  163. if ($(`#skill-nav-mastery-${id} .progress-bar`)[0]) {
  164. $(`#skill-nav-mastery-${id} .progress-bar`)[0].style.width =
  165. (MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100 + '%';
  166. if (MASTERY[id].pool < getMasteryPoolTotalXP(id)) {
  167. $(`#skill-nav-mastery-${id}`)[0].style.setProperty('background', 'rgb(76,80,84)', 'important');
  168. $(`#skill-nav-mastery-${id} .progress-bar`)[0].className = 'progress-bar bg-warning';
  169. } else {
  170. $(`#skill-nav-mastery-${id}`)[0].style.setProperty('background', 'rgb(48,199,141)', 'success');
  171. $(`#skill-nav-mastery-${id} .progress-bar`)[0].className = 'progress-bar bg-success';
  172. }
  173. const tip = $(`#skill-nav-mastery-${id}`)[0]._tippy;
  174. tip.setContent((Math.min(1, MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100).toFixed(2) + '%');
  175. } else {
  176. const skillItem = $(`#skill-nav-name-${id}`)[0].parentNode;
  177. skillItem.style.flexWrap = 'wrap';
  178. skillItem.style.setProperty('padding-top', '.25rem', 'important');
  179. const progress = document.createElement('div');
  180. const progressBar = document.createElement('div');
  181. progress.id = `skill-nav-mastery-${id}`;
  182. progress.className = 'progress active pointer-enabled';
  183. progress.style.height = '6px';
  184. progress.style.width = '100%';
  185. progress.style.margin = '.25rem 0rem';
  186. if (MASTERY[id].pool < getMasteryPoolTotalXP(id)) {
  187. progress.style.setProperty('background', 'rgb(76,80,84)', 'important');
  188. progressBar.className = 'progress-bar bg-warning';
  189. } else {
  190. progress.style.setProperty('background', 'rgb(48,199,141)', 'success');
  191. progressBar.className = 'progress-bar bg-success';
  192. }
  193. progressBar.style.width = (MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100 + '%';
  194. progress.appendChild(progressBar);
  195. skillItem.appendChild(progress);
  196. tippy($(`#skill-nav-mastery-${id}`)[0], {
  197. placement: 'right',
  198. content: ((MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100).toFixed(2) + '%',
  199. });
  200. }
  201. }
  202. }
  203. }, 5000);
  204. snippet.end();
  205.  
  206. ///////////////////
  207. //MasteryBuyer.js//
  208. ///////////////////
  209. snippet.name = 'MasteryBuyer.js';
  210. snippet.start();
  211. // methods to buy base mastery levels
  212. window.masteryBuyer = {
  213. poolXpPerItem: 500000,
  214. };
  215.  
  216. masteryBuyer.availXp = (skillID, minPercent = 95) => {
  217. let minPool = MASTERY[skillID].xp.length * masteryBuyer.poolXpPerItem * minPercent / 100;
  218. return MASTERY[skillID].pool - minPool;
  219. }
  220.  
  221. masteryBuyer.currentBase = (skillID) => {
  222. return Math.min(...MASTERY[skillID].xp.map((_, masteryID) => getMasteryLevel(skillID, masteryID)));
  223. }
  224.  
  225. masteryBuyer.maxAffordableBase = (skillID, minPercent = 95) => {
  226. let xp = masteryBuyer.availXp(skillID, minPercent);
  227. // make bins with mastery levels
  228. let bins = [];
  229. for (let i = 0; i < 100; i++) {
  230. bins[i] = [];
  231. }
  232. MASTERY[skillID].xp.forEach((_, masteryID) => {
  233. let level = getMasteryLevel(skillID, masteryID);
  234. bins[level].push(masteryID);
  235. });
  236. // level one at a time
  237. let maxBase = 0;
  238. bins.forEach((x, i) => {
  239. if (i >= 99) {
  240. return;
  241. }
  242. if (x.length === 0) {
  243. return;
  244. }
  245. let xpRequired = (exp.level_to_xp(i + 1) - exp.level_to_xp(i)) * x.length;
  246. xp -= xpRequired;
  247. if (xp >= 0) {
  248. maxBase = i + 1;
  249. x.forEach(y => bins[i + 1].push(y));
  250. }
  251. });
  252. maxBase = maxBase > 99 ? 99 : maxBase;
  253. return maxBase;
  254. }
  255.  
  256. masteryBuyer.increaseBase = (skillID, minPercent = 95, levelCap = 99) => {
  257. // buy until goal
  258. let goal = masteryBuyer.maxAffordableBase(skillID, minPercent);
  259. if (goal === 0) {
  260. goal = masteryBuyer.currentBase(skillID);
  261. }
  262. if (goal > levelCap) {
  263. goal = levelCap;
  264. }
  265. MASTERY[skillID].xp.forEach((_, masteryID) => {
  266. let level = getMasteryLevel(skillID, masteryID);
  267. if (level >= goal) {
  268. return;
  269. }
  270. masteryPoolLevelUp = goal - level;
  271. levelUpMasteryWithPool(skillID, masteryID);
  272. });
  273. // spend remainder on goal + 1
  274. const xpRequired = exp.level_to_xp(goal + 1) - exp.level_to_xp(goal);
  275. let count = Math.floor(masteryBuyer.availXp(skillID, minPercent) / xpRequired);
  276. masteryPoolLevelUp = 1;
  277. MASTERY[skillID].xp.forEach((_, masteryID) => {
  278. if (count === 0) {
  279. return;
  280. }
  281. let level = getMasteryLevel(skillID, masteryID);
  282. if (level > goal || level >= levelCap) {
  283. return;
  284. }
  285. count--;
  286. levelUpMasteryWithPool(skillID, masteryID);
  287. });
  288. // update total mastery
  289. updateTotalMastery(skillID);
  290. }
  291.  
  292. masteryBuyer.overview = (minPercent = 95) => {
  293. Object.getOwnPropertyNames(SKILLS).forEach(skillID => {
  294. const skill = SKILLS[skillID];
  295. if (!skill.hasMastery) {
  296. return;
  297. }
  298. const maxBase = masteryBuyer.maxAffordableBase(skillID, minPercent);
  299. if (maxBase === 0) {
  300. return;
  301. }
  302. const currentBase = masteryBuyer.currentBase(skillID);
  303. console.log(`${skill.name}: ${currentBase} -> ${maxBase}`);
  304. });
  305. }
  306.  
  307. masteryBuyer.remaining = (skillID, target = 99) => {
  308. let xp = 0;
  309. let xpTarget = exp.level_to_xp(target);
  310. MASTERY[skillID].xp.forEach(masteryXp => {
  311. xp += Math.max(0, xpTarget - masteryXp);
  312. });
  313. xp = Math.round(xp)
  314. console.log(formatNumber(xp))
  315. return xp
  316. }
  317. snippet.end();
  318.  
  319. ///////////////////////
  320. //PrintSynergyList.js//
  321. ///////////////////////
  322. snippet.name = 'PrintSynergyList.js';
  323. snippet.start();
  324. // functions to print synergies per category (cb vs non-cb)
  325. printSynergy = (x, y) => console.log('- [ ]',
  326. x.summoningID,
  327. parseInt(y),
  328. items[x.itemID].name,
  329. items[summoningItems[y].itemID].name,
  330. SUMMONING.Synergies[x.summoningID][y].description,
  331. SUMMONING.Synergies[x.summoningID][y].modifiers
  332. );
  333.  
  334. printCombatSynergyList = () => {
  335. // get combat synergies
  336. summoningItems.filter(x => items[x.itemID].summoningMaxHit).map(x => {
  337. for (y in SUMMONING.Synergies[x.summoningID]) {
  338. printSynergy(x, y);
  339. }
  340. });
  341. }
  342.  
  343. printNonCombatSynergyList = () => {
  344. // get non-combat synergies
  345. summoningItems.filter(x => !items[x.itemID].summoningMaxHit).map(x => {
  346. for (y in SUMMONING.Synergies[x.summoningID]) {
  347. printSynergy(x, y);
  348. }
  349. });
  350. }
  351. snippet.end();
  352.  
  353. /////////////////////
  354. //QuickEquipCape.js//
  355. /////////////////////
  356. snippet.name = 'QuickEquipCape.js';
  357. snippet.start();
  358. // Quick Equip Max/Comp Cape
  359. quickEquipSkillcape = (skill) => {
  360. const capes = [
  361. Items.Cape_of_Completion,
  362. Items.Max_Skillcape,
  363. skillcapeItems[skill],
  364. ];
  365. for (let i = 0; i < capes.length; i++) {
  366. const capeId = capes[i];
  367. if (player.equipment.checkForItemID(capeId)) {
  368. notifyPlayer(skill, `${items[capeId].name} is already equipped.`, "info");
  369. return;
  370. }
  371. const bankId = getBankId(capeId);
  372. if (bankId === -1) {
  373. continue;
  374. }
  375. if (!player.equipItem(capeId, player.selectedEquipmentSet)) {
  376. continue;
  377. }
  378. notifyPlayer(skill, `${items[capeId].name} Equipped.`, "success");
  379. if (skill === 0) {
  380. updateWCRates();
  381. }
  382. return;
  383. }
  384. notifyPlayer(skill, "There's no " + setToUppercase(Skills[skill]) + " Skillcape in your bank *shrug*", "danger");
  385. }
  386. snippet.end();
  387.  
  388. ////////////////////
  389. //ReclaimTokens.js//
  390. ////////////////////
  391. snippet.name = 'ReclaimTokens.js';
  392. snippet.start();
  393. // reclaim tokens
  394. window.reclaimMasteryTokens = () => {
  395. skillXP.forEach((_, s) => {
  396. if (MASTERY[s] === undefined) {
  397. return;
  398. }
  399. const id = Items['Mastery_Token_' + Skills[s]];
  400. const p = Math.floor((MASTERY[s].pool - getMasteryPoolTotalXP(s) ) / Math.floor(getMasteryPoolTotalXP(s)*0.001));
  401. const m = game.stats.Items.statsMap.get(id).stats.get(ItemStats.TimesFound);
  402. const o = getBankQty(id);
  403. const a = Math.min(p, m - o);
  404. const b = getBankId(id);
  405. if (a > 0 && b >= 0) {
  406. bank[b].qty += a;
  407. MASTERY[s].pool -= a * Math.floor(getMasteryPoolTotalXP(s)*0.001);
  408. snippets.log('reclaimed', a, Skills[s], 'tokens');
  409. }
  410. });
  411. }
  412.  
  413. snippet.end();
  414.  
  415. /////////////////////
  416. //RemoveElements.js//
  417. /////////////////////
  418. snippet.name = 'RemoveElements.js';
  419. snippet.start();
  420. // remove various elements
  421. // combat
  422. document.getElementById('offline-combat-alert').remove();
  423.  
  424. // summoning marks
  425. // green
  426. document.getElementById('summoning-category-0').children[0].children[0].children[2].remove();
  427. // orange and red
  428. document.getElementById('summoning-category-0').children[0].children[0].children[1].remove();
  429.  
  430. // summoning tablets
  431. document.getElementById('summoning-category-1').children[0].children[0].children[0].remove()
  432.  
  433. // alt. magic
  434. document.getElementById('magic-container').children[0].children[1].remove();
  435.  
  436. // cloud saving
  437. document.getElementById('header-cloud-save-time').remove();
  438. document.getElementById('header-cloud-save-btn-connected').remove();
  439. snippet.end();
  440.  
  441. ///////////////////
  442. //RerollSlayer.js//
  443. ///////////////////
  444. snippet.name = 'RerollSlayer.js';
  445. snippet.start();
  446. //reroll slayer task until desired task is met
  447. window.rerollSlayerTask = (monsterIDs, tier, extend = true) => {
  448. if (snippets.stopRerolling) {
  449. return;
  450. }
  451. const task = combatManager.slayerTask;
  452. const taskID = task.monster.id;
  453. const taskName = MONSTERS[taskID].name;
  454. if (!combatManager.slayerTask.taskTimer.active) {
  455. // only do something if slayer task timer is not running
  456. if (!combatManager.slayerTask.active || !monsterIDs.includes(taskID)) {
  457. // roll task if we don't have one, or if it has the wrong monster
  458. console.log(`rerolling ${taskName} for tier ${tier} task ${monsterIDs.map(monsterID => MONSTERS[monsterID].name).join(', ')}`);
  459. combatManager.slayerTask.selectTask(tier, true, true, false);
  460. } else if (extend && !task.extended) {
  461. // extend task if it is the right monster
  462. console.log(`extending ${taskName}`);
  463. combatManager.slayerTask.extendTask();
  464. }
  465. }
  466. setTimeout(() => rerollSlayerTask(monsterIDs, tier, extend), 1000);
  467. }
  468. snippet.end();
  469.  
  470. /////////////////
  471. //ShardsUsed.js//
  472. /////////////////
  473. snippet.name = 'ShardsUsed.js';
  474. snippet.start();
  475. // compute total shards used
  476. shardsUsed = () => {
  477. // compute amount of gp spent on summoning shards that have been used (for summoning or agility obstacles)
  478. items.map((x, i) => [x, i])
  479. .filter(x => x[0].type === 'Shard' && x[0].category === 'Summoning')
  480. .map(x => x[1])
  481. .map(x => (itemStats[x].stats[0] - getBankQty(x) - itemStats[x].stats[1]) * items[x].buysFor)
  482. .reduce((a, b) => a + b, 0);
  483. }
  484. snippet.end();
  485.  
  486. ///////////////////
  487. //SpawnAhrenia.js//
  488. ///////////////////
  489. snippet.name = 'SpawnAhrenia.js';
  490. snippet.start();
  491. // spawn Ahrenia
  492. window.spawnAhrenia = (phaseToSpawn = 1) => {
  493. // run
  494. combatManager.runCombat();
  495. // set respawn to 0
  496. if (!petUnlocked[0]) {
  497. unlockPet(0);
  498. }
  499. PETS[0].modifiers.decreasedMonsterRespawnTimer = 0;
  500. player.computeAllStats();
  501. PETS[0].modifiers.decreasedMonsterRespawnTimer = 3000 - TICK_INTERVAL - player.modifiers.decreasedMonsterRespawnTimer + player.modifiers.increasedMonsterRespawnTimer;
  502. player.computeAllStats();
  503. // unlock itm
  504. dungeonCompleteCount[Dungeons.Fire_God_Dungeon] = Math.max(
  505. dungeonCompleteCount[Dungeons.Fire_God_Dungeon],
  506. 1,
  507. );
  508. skillLevel[Skills.Slayer] = Math.max(
  509. skillLevel[Skills.Slayer],
  510. 90,
  511. );
  512. // skip to desired phase
  513. combatManager.selectDungeon(15);
  514. combatManager.dungeonProgress = 19 + phaseToSpawn;
  515. combatManager.loadNextEnemy();
  516. }
  517. snippet.end();
  518.  
  519. ////////////////////
  520. //UnlimitedPool.js//
  521. ////////////////////
  522. snippet.name = 'UnlimitedPool.js';
  523. snippet.start();
  524. // don't cap pool xp
  525. eval(addMasteryXPToPool.toString()
  526. .replace('MASTERY[skill].pool>getMasteryPoolTotalXP(skill)', 'false')
  527. .replace(/^function (\w+)/, "window.$1 = function")
  528. );
  529.  
  530. // don't cap token claiming
  531. eval(claimToken.toString()
  532. .replace('qty>=tokensToFillPool', 'false')
  533. .replace(/^function (\w+)/, "window.$1 = function")
  534. );
  535. snippet.end();
  536.  
  537. // footer start
  538. }
  539.  
  540. function loadScript() {
  541. if (typeof isLoaded !== typeof undefined && isLoaded) {
  542. // Only load script after game has opened
  543. clearInterval(scriptLoader);
  544. startSnippets();
  545. }
  546. }
  547.  
  548. const scriptLoader = setInterval(loadScript, 200);
  549. });