Melvor Snippets

Collection of various snippets

当前为 2022-01-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Melvor Snippets
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.11
  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. //FixPerformSkillProcess.js//
  119. /////////////////////////////
  120. snippet.name = 'FixPerformSkillProcess.js';
  121. snippet.start();
  122. // fix perform skill process
  123. eval(performSkillProcess.toString().replace(
  124. 'if(!confirmedAdded&&!offline)return false;',
  125. 'if (!confirmedAdded && !ignoreBankFull && !offline) return false;'
  126. ).replace(
  127. /^function (\w+)/,
  128. 'window.$1 = function'
  129. ));
  130. snippet.end();
  131.  
  132. /////////////////////////
  133. //GetLocalisationKey.js//
  134. /////////////////////////
  135. snippet.name = 'GetLocalisationKey.js';
  136. snippet.start();
  137. // Get Localisation Key for a given string
  138. getLocalisationKey = (text) => {
  139. const list = []
  140. for (const key in loadedLangJson) {
  141. for (const identifier in loadedLangJson[key]) {
  142. if (loadedLangJson[key][identifier] === text) {
  143. list.push({key: key, identifier: identifier});
  144. }
  145. }
  146. }
  147. return list;
  148. }
  149. snippet.end();
  150.  
  151. //////////////////
  152. //MasteryBars.js//
  153. //////////////////
  154. snippet.name = 'MasteryBars.js';
  155. snippet.start();
  156. // Add Mastery Bars
  157. setInterval(() => {
  158. for (const id in SKILLS) {
  159. if (SKILLS[id].hasMastery) {
  160. if ($(`#skill-nav-mastery-${id} .progress-bar`)[0]) {
  161. $(`#skill-nav-mastery-${id} .progress-bar`)[0].style.width =
  162. (MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100 + '%';
  163. if (MASTERY[id].pool < getMasteryPoolTotalXP(id)) {
  164. $(`#skill-nav-mastery-${id}`)[0].style.setProperty('background', 'rgb(76,80,84)', 'important');
  165. $(`#skill-nav-mastery-${id} .progress-bar`)[0].className = 'progress-bar bg-warning';
  166. } else {
  167. $(`#skill-nav-mastery-${id}`)[0].style.setProperty('background', 'rgb(48,199,141)', 'success');
  168. $(`#skill-nav-mastery-${id} .progress-bar`)[0].className = 'progress-bar bg-success';
  169. }
  170. const tip = $(`#skill-nav-mastery-${id}`)[0]._tippy;
  171. tip.setContent((Math.min(1, MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100).toFixed(2) + '%');
  172. } else {
  173. const skillItem = $(`#skill-nav-name-${id}`)[0].parentNode;
  174. skillItem.style.flexWrap = 'wrap';
  175. skillItem.style.setProperty('padding-top', '.25rem', 'important');
  176. const progress = document.createElement('div');
  177. const progressBar = document.createElement('div');
  178. progress.id = `skill-nav-mastery-${id}`;
  179. progress.className = 'progress active pointer-enabled';
  180. progress.style.height = '6px';
  181. progress.style.width = '100%';
  182. progress.style.margin = '.25rem 0rem';
  183. if (MASTERY[id].pool < getMasteryPoolTotalXP(id)) {
  184. progress.style.setProperty('background', 'rgb(76,80,84)', 'important');
  185. progressBar.className = 'progress-bar bg-warning';
  186. } else {
  187. progress.style.setProperty('background', 'rgb(48,199,141)', 'success');
  188. progressBar.className = 'progress-bar bg-success';
  189. }
  190. progressBar.style.width = (MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100 + '%';
  191. progress.appendChild(progressBar);
  192. skillItem.appendChild(progress);
  193. tippy($(`#skill-nav-mastery-${id}`)[0], {
  194. placement: 'right',
  195. content: ((MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100).toFixed(2) + '%',
  196. });
  197. }
  198. }
  199. }
  200. }, 5000);
  201. snippet.end();
  202.  
  203. ///////////////////
  204. //MasteryBuyer.js//
  205. ///////////////////
  206. snippet.name = 'MasteryBuyer.js';
  207. snippet.start();
  208. // methods to buy base mastery levels
  209. window.masteryBuyer = {
  210. poolXpPerItem: 500000,
  211. };
  212.  
  213. masteryBuyer.availXp = (skillID, minPercent = 95) => {
  214. let minPool = MASTERY[skillID].xp.length * masteryBuyer.poolXpPerItem * minPercent / 100;
  215. return MASTERY[skillID].pool - minPool;
  216. }
  217.  
  218. masteryBuyer.currentBase = (skillID) => {
  219. return Math.min(...MASTERY[skillID].xp.map((_, masteryID) => getMasteryLevel(skillID, masteryID)));
  220. }
  221.  
  222. masteryBuyer.maxAffordableBase = (skillID, minPercent = 95) => {
  223. let xp = masteryBuyer.availXp(skillID, minPercent);
  224. // make bins with mastery levels
  225. let bins = [];
  226. for (let i = 0; i < 100; i++) {
  227. bins[i] = [];
  228. }
  229. MASTERY[skillID].xp.forEach((_, masteryID) => {
  230. let level = getMasteryLevel(skillID, masteryID);
  231. bins[level].push(masteryID);
  232. });
  233. // level one at a time
  234. let maxBase = 0;
  235. bins.forEach((x, i) => {
  236. if (i >= 99) {
  237. return;
  238. }
  239. if (x.length === 0) {
  240. return;
  241. }
  242. let xpRequired = (exp.level_to_xp(i + 1) - exp.level_to_xp(i)) * x.length;
  243. xp -= xpRequired;
  244. if (xp >= 0) {
  245. maxBase = i + 1;
  246. x.forEach(y => bins[i + 1].push(y));
  247. }
  248. });
  249. maxBase = maxBase > 99 ? 99 : maxBase;
  250. return maxBase;
  251. }
  252.  
  253. masteryBuyer.increaseBase = (skillID, minPercent = 95, levelCap = 99) => {
  254. // buy until goal
  255. let goal = masteryBuyer.maxAffordableBase(skillID, minPercent);
  256. if (goal === 0) {
  257. goal = masteryBuyer.currentBase(skillID);
  258. }
  259. if (goal > levelCap) {
  260. goal = levelCap;
  261. }
  262. MASTERY[skillID].xp.forEach((_, masteryID) => {
  263. let level = getMasteryLevel(skillID, masteryID);
  264. if (level >= goal) {
  265. return;
  266. }
  267. masteryPoolLevelUp = goal - level;
  268. levelUpMasteryWithPool(skillID, masteryID);
  269. });
  270. // spend remainder on goal + 1
  271. const xpRequired = exp.level_to_xp(goal + 1) - exp.level_to_xp(goal);
  272. let count = Math.floor(masteryBuyer.availXp(skillID, minPercent) / xpRequired);
  273. masteryPoolLevelUp = 1;
  274. MASTERY[skillID].xp.forEach((_, masteryID) => {
  275. if (count === 0) {
  276. return;
  277. }
  278. let level = getMasteryLevel(skillID, masteryID);
  279. if (level > goal || level >= levelCap) {
  280. return;
  281. }
  282. count--;
  283. levelUpMasteryWithPool(skillID, masteryID);
  284. });
  285. // update total mastery
  286. updateTotalMastery(skillID);
  287. }
  288.  
  289. masteryBuyer.overview = (minPercent = 95) => {
  290. Object.getOwnPropertyNames(SKILLS).forEach(skillID => {
  291. const skill = SKILLS[skillID];
  292. if (!skill.hasMastery) {
  293. return;
  294. }
  295. const maxBase = masteryBuyer.maxAffordableBase(skillID, minPercent);
  296. if (maxBase === 0) {
  297. return;
  298. }
  299. const currentBase = masteryBuyer.currentBase(skillID);
  300. console.log(`${skill.name}: ${currentBase} -> ${maxBase}`);
  301. });
  302. }
  303.  
  304. masteryBuyer.remaining = (skillID, target = 99) => {
  305. let xp = 0;
  306. let xpTarget = exp.level_to_xp(target);
  307. MASTERY[skillID].xp.forEach(masteryXp => {
  308. xp += Math.max(0, xpTarget - masteryXp);
  309. });
  310. xp = Math.round(xp)
  311. console.log(formatNumber(xp))
  312. return xp
  313. }
  314. snippet.end();
  315.  
  316. ///////////////////////
  317. //PrintSynergyList.js//
  318. ///////////////////////
  319. snippet.name = 'PrintSynergyList.js';
  320. snippet.start();
  321. // functions to print synergies per category (cb vs non-cb)
  322. printSynergy = (x, y) => console.log('- [ ]',
  323. x.summoningID,
  324. parseInt(y),
  325. items[x.itemID].name,
  326. items[summoningItems[y].itemID].name,
  327. SUMMONING.Synergies[x.summoningID][y].description,
  328. SUMMONING.Synergies[x.summoningID][y].modifiers
  329. );
  330.  
  331. printCombatSynergyList = () => {
  332. // get combat synergies
  333. summoningItems.filter(x => items[x.itemID].summoningMaxHit).map(x => {
  334. for (y in SUMMONING.Synergies[x.summoningID]) {
  335. printSynergy(x, y);
  336. }
  337. });
  338. }
  339.  
  340. printNonCombatSynergyList = () => {
  341. // get non-combat synergies
  342. summoningItems.filter(x => !items[x.itemID].summoningMaxHit).map(x => {
  343. for (y in SUMMONING.Synergies[x.summoningID]) {
  344. printSynergy(x, y);
  345. }
  346. });
  347. }
  348. snippet.end();
  349.  
  350. /////////////////////
  351. //QuickEquipCape.js//
  352. /////////////////////
  353. snippet.name = 'QuickEquipCape.js';
  354. snippet.start();
  355. // Quick Equip Max/Comp Cape
  356. quickEquipSkillcape = (skill) => {
  357. const capes = [
  358. Items.Cape_of_Completion,
  359. Items.Max_Skillcape,
  360. skillcapeItems[skill],
  361. ];
  362. for (let i = 0; i < capes.length; i++) {
  363. const capeId = capes[i];
  364. if (player.equipment.checkForItemID(capeId)) {
  365. notifyPlayer(skill, `${items[capeId].name} is already equipped.`, "info");
  366. return;
  367. }
  368. const bankId = getBankId(capeId);
  369. if (bankId === -1) {
  370. continue;
  371. }
  372. if (!player.equipItem(capeId, player.selectedEquipmentSet)) {
  373. continue;
  374. }
  375. notifyPlayer(skill, `${items[capeId].name} Equipped.`, "success");
  376. if (skill === 0) {
  377. updateWCRates();
  378. }
  379. return;
  380. }
  381. notifyPlayer(skill, "There's no " + setToUppercase(Skills[skill]) + " Skillcape in your bank *shrug*", "danger");
  382. }
  383. snippet.end();
  384.  
  385. ////////////////////
  386. //ReclaimTokens.js//
  387. ////////////////////
  388. snippet.name = 'ReclaimTokens.js';
  389. snippet.start();
  390. // reclaim tokens
  391. window.reclaimMasteryTokens = () => {
  392. skillXP.forEach((_, s) => {
  393. if (MASTERY[s] === undefined) {
  394. return;
  395. }
  396. const id = Items['Mastery_Token_' + Skills[s]];
  397. const p = Math.floor((MASTERY[s].pool - getMasteryPoolTotalXP(s) ) / Math.floor(getMasteryPoolTotalXP(s)*0.001));
  398. const m = game.stats.Items.statsMap.get(id).stats.get(ItemStats.TimesFound);
  399. const o = getBankQty(id);
  400. const a = Math.min(p, m - o);
  401. const b = getBankId(id);
  402. if (a > 0 && b >= 0) {
  403. bank[b].qty += a;
  404. MASTERY[s].pool -= a * Math.floor(getMasteryPoolTotalXP(s)*0.001);
  405. snippets.log('reclaimed', a, Skills[s], 'tokens');
  406. }
  407. });
  408. }
  409.  
  410. snippet.end();
  411.  
  412. /////////////////////
  413. //RemoveElements.js//
  414. /////////////////////
  415. snippet.name = 'RemoveElements.js';
  416. snippet.start();
  417. // remove various elements
  418. // combat
  419. document.getElementById('offline-combat-alert').remove();
  420.  
  421. // summoning marks
  422. // green
  423. document.getElementById('summoning-category-0').children[0].children[0].children[2].remove();
  424. // orange and red
  425. document.getElementById('summoning-category-0').children[0].children[0].children[1].remove();
  426.  
  427. // summoning tablets
  428. document.getElementById('summoning-category-1').children[0].children[0].children[0].remove()
  429.  
  430. // alt. magic
  431. document.getElementById('magic-container').children[0].children[1].remove();
  432.  
  433. // cloud saving
  434. document.getElementById('header-cloud-save-time').remove();
  435. document.getElementById('header-cloud-save-btn-connected').remove();
  436.  
  437. // minibar-max-cape
  438. document.getElementById('minibar-max-cape').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 (window.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. });