Advertisement
iradap

AutoHeal NI

Feb 14th, 2021
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. // ==UserScript==
  2. // @name AutoHeal NI
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description try to take over the world!
  6. // @author MiensnyTrzaski
  7. // @match https://*.margonem.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. const getBestItem=(diff,time=500)=>new Promise(res=>
  12. setTimeout(()=>
  13. res(Object.values(Engine.heroEquipment.getInvItems())
  14. .filter(a=>a._cachedStats.hasOwnProperty("leczy"))
  15. .filter(a=>a._cachedStats.leczy<=diff)
  16. .sort((first,second)=>second._cachedStats.leczy-first._cachedStats.leczy)[0])
  17. ,time))
  18.  
  19.  
  20. const healHero=async ()=>{
  21. let heroHP=Engine.hero.d.warrior_stats.hp;
  22. let bestHealItem=await getBestItem(Engine.hero.d.warrior_stats.maxhp-heroHP);
  23. while(bestHealItem){
  24. Engine.heroEquipment.sendUseRequest(bestHealItem);
  25. heroHP+=parseInt(bestHealItem._cachedStats.leczy);
  26. bestHealItem=await getBestItem(Engine.hero.d.warrior_stats.maxhp-heroHP);
  27. }
  28. }
  29.  
  30. const main=(battleLog, warriorsInfo)=>{
  31. if(battleLog.some(a=>a.includes("winner")) && !Engine.dead && Engine.hero.d.warrior_stats.maxhp!==Engine.hero.d.warrior_stats.hp){
  32. healHero();
  33. }
  34. }
  35.  
  36. (oldFun=>{
  37. Engine.communication.dispatcher.on_f=a=>{
  38. if(a.hasOwnProperty('m')){
  39. main(a.m,Object.values(a.w));
  40. }
  41. oldFun(a);
  42. };
  43. })(Engine.communication.dispatcher.on_f);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement