Advertisement
Guest User

Untitled

a guest
Feb 10th, 2023
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         AutoHeal z potek i fullheal
  3. // @version      1.4
  4. // @match        https://*.margonem.pl/
  5. // @grant        none
  6. // @author       Bancewald
  7. // ==/UserScript==
  8.  
  9. //1.1 - dodane potki ktore lecza % hp
  10. //1.2 - naprawiono zapętlenia
  11. //1.3 - zuzywa teraz potki pelnego leczenia po kolei
  12. //1.4 - poprawka od Wexurro na nowy interfejs
  13.  
  14. async function waitForSeconds(time) {
  15.   time *= 1000
  16.   return new Promise(resolve => {
  17.     setTimeout(() => {
  18.       resolve();
  19.     }, time);
  20.   });
  21. }
  22.  
  23.  
  24. async function run() {
  25.     await waitForSeconds(3) //Czekanie chwile na załadowanie gry
  26.     const updateHeroHp = (item) => {
  27.         if(item._cachedStats.hasOwnProperty("leczy")){
  28.             Engine.hero.d.warrior_stats.hp = Engine.hero.d.warrior_stats.hp + parseInt(item._cachedStats.leczy)
  29.         }
  30.         else if(item._cachedStats.hasOwnProperty("fullheal")){
  31.             if(item._cachedStats.fullheal >= Engine.hero.d.warrior_stats.maxhp - Engine.hero.d.warrior_stats.hp){
  32.                 Engine.hero.d.warrior_stats.hp = Engine.hero.d.warrior_stats.maxhp
  33.             } else {
  34.                 Engine.hero.d.warrior_stats.hp = Engine.hero.d.warrior_stats.hp + parseInt(item._cachedStats.fullheal)
  35.             }
  36.         }
  37.         else if(item._cachedStats.hasOwnProperty("perheal")){
  38.             Engine.hero.d.warrior_stats.hp = Engine.hero.d.warrior_stats.hp + parseInt((item._cachedStats.perheal/100)*Engine.hero.d.warrior_stats.maxhp)
  39.     }
  40.     }
  41.  
  42.     const useItem = item => {
  43.         const {
  44.             name,
  45.             id
  46.         } = item;
  47.         updateHeroHp(item)
  48.         window._g(`moveitem&st=1&id=${id}`, () => {
  49.             setTimeout(autoHeal, 100);
  50.         });
  51.     }
  52.  
  53.     const getMaxHealVal = items => {
  54.         if (items.length > 0) {
  55.             return items.reduce((first, second) => first._cachedStats.leczy >= second._cachedStats.leczy ? first : second)
  56.         }
  57.     }
  58.  
  59.     const getMaxHealValFH = items => {
  60.         if (items.length > 0) {
  61.             return items.reduce((first, second) => first._cachedStats.fullheal >= second._cachedStats.fullheal ? first : second)
  62.         }
  63.     }
  64.  
  65.     const getMaxHealValperheal = items => {
  66.         if (items.length > 0) {
  67.             return items.reduce((first, second) => first._cachedStats.perheal >= second._cachedStats.perheal ? first : second)
  68.         }
  69.     }
  70.  
  71.     const autoHeal = () => {
  72.         let {
  73.             hp,
  74.             maxhp,
  75.             lvl
  76.         } = Engine.hero.d;
  77.  
  78.         if (hp == undefined) {
  79.             hp = Engine.hero.d.warrior_stats.hp
  80.         }
  81.         if (maxhp == undefined){
  82.             maxhp = Engine.hero.d.warrior_stats.maxhp
  83.         }
  84.  
  85.         if (hp < maxhp && !Engine.dead) {
  86.             const items = Engine.items.fetchLocationItems("g")
  87.                 .filter(item => item._cachedStats.hasOwnProperty("leczy"))
  88.                 .filter(item => item._cachedStats.leczy <= maxhp - hp)
  89.                 .filter(item => item._cachedStats.leczy > 500)
  90.                 .filter(item => !item._cachedStats.hasOwnProperty("lvl") || (item._cachedStats.hasOwnProperty("lvl") && item._cachedStats.lvl <= lvl))
  91.                 .filter(item => !item._cachedStats.hasOwnProperty("timelimit") || (item._cachedStats.hasOwnProperty("timelimit") && !item._cachedStats.timelimit.includes(",")));
  92.  
  93.             const items_fh = Engine.items.fetchLocationItems("g")
  94.                 .filter(item => item._cachedStats.hasOwnProperty("fullheal"))
  95.                 .filter(item => !item._cachedStats.hasOwnProperty("lvl") || (item._cachedStats.hasOwnProperty("lvl") && item._cachedStats.lvl <= lvl))
  96.                 .filter(item => !item._cachedStats.hasOwnProperty("timelimit") || (item._cachedStats.hasOwnProperty("timelimit") && !item._cachedStats.timelimit.includes(",")))
  97.                 .sort((a, b) => {
  98.                     let aHeal = parseInt(a._cachedStats.fullheal)
  99.                     let bHeal = parseInt(b._cachedStats.fullheal)
  100.                     if(aHeal == bHeal) return 0
  101.                     else if(aHeal < bHeal) return -1
  102.                     else return 1
  103.                 });
  104.  
  105.             const items_percent = Engine.items.fetchLocationItems("g")
  106.                 .filter(item => item._cachedStats.hasOwnProperty("perheal"))
  107.                 .filter(item => item._cachedStats.perheal <= (maxhp - hp) * 100 / maxhp)
  108.                 .filter(item => !item._cachedStats.hasOwnProperty("lvl") || (item._cachedStats.hasOwnProperty("lvl") && item._cachedStats.lvl <= lvl))
  109.                 .filter(item => !item._cachedStats.hasOwnProperty("timelimit") || (item._cachedStats.hasOwnProperty("timelimit") && !item._cachedStats.timelimit.includes(",")));
  110.  
  111.             let item;
  112.             if (items.length > 0) item = getMaxHealVal(items);
  113.             else if (items_percent.length > 0) item = getMaxHealValperheal(items_percent);
  114.             else if (items_fh.length > 0) item = getMaxHealValFH(items_fh);
  115.  
  116.             if (item !== undefined) {
  117.                 useItem(item);
  118.             }
  119.         }
  120.     }
  121.  
  122.     window.API.addCallbackToEvent("close_battle", autoHeal);
  123. }
  124.  
  125. run()
  126.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement