Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. // ==UserScript==
  2. // @name AutoHeal z potek
  3. // @version 1.0
  4. // @match http://*.margonem.pl/
  5. // @match https://*.margonem.pl/
  6. // @grant none
  7. // @author adi wilk
  8. // ==/UserScript==
  9.  
  10. (Engine => {
  11. const useItem = item => {
  12. const {
  13. name,
  14. id
  15. } = item;
  16.  
  17. //window.log(`Uleczono potką ${name}.`);
  18. window._g(`moveitem&st=1&id=${id}`, () => {
  19. setTimeout(autoHeal, 100);
  20. });
  21. }
  22.  
  23. const getMaxHealVal = items => {
  24. if (items.length > 0) {
  25. return items.reduce((first, second) => first._cachedStats.leczy >= second._cachedStats.leczy ? first : second)
  26. }
  27. }
  28.  
  29. const autoHeal = () => {
  30. const {
  31. hp,
  32. maxhp,
  33. lvl
  34. } = Engine.hero.d.warrior_stats;
  35.  
  36. if (hp < maxhp && !Engine.dead) {
  37. const items = Engine.items.fetchLocationItems("g")
  38. .filter(item => item._cachedStats.hasOwnProperty("leczy"))
  39. .filter(item => item._cachedStats.leczy <= maxhp - hp)
  40. .filter(item => !item._cachedStats.hasOwnProperty("lvl") || (item._cachedStats.hasOwnProperty("lvl") && item._cachedStats.lvl <= lvl))
  41. .filter(item => !item._cachedStats.hasOwnProperty("timelimit") || (item._cachedStats.hasOwnProperty("timelimit") && !item._cachedStats.timelimit.includes(",")));
  42.  
  43. const item = getMaxHealVal(items);
  44. if (item !== undefined) useItem(item);
  45. }
  46. }
  47.  
  48. window.API.addCallbackToEvent("close_battle", autoHeal);
  49. })(window.Engine)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement