Advertisement
iradap

Autoheal com ni

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