affekk

Untitled

Mar 26th, 2022 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1.  
  2. // Sekcja konfiguracji
  3. const config = {
  4. putAuction: {
  5. // Czy wystawianie na aukcje ma być włączone
  6. enabled: true,
  7. // Za ile można licytować
  8. // Wpisz '', jeśli ma nie wystawiać na licytację
  9. bidPrice: '',
  10. // Za ile ma wystawić
  11. // Wpisz '', jeśli ma nie wystawiać na kup teraz
  12. buyPrice: '1,45m',
  13. // Na ile wystawić (czas w godzinach, maks. 168h)
  14. time: 168,
  15. // Minimalny poziom przemiotu do wystawienia
  16. minLvl: 10,
  17. // Maksymalny poziom przedmiotu do wystawienia
  18. maxLvl: 270,
  19. },
  20. sendGold: {
  21. // Czy wysyłanie golda ma być włączone
  22. enabled: true,
  23. // Minimalna ilość złota, od której ma wysyłać
  24. minAmount: '5m',
  25. // Ilość złota, którą ma zostawiać
  26. saveGold: '4m',
  27. // Na jaki nick ma wysyłać
  28. target: 'palis jr'
  29. },
  30. getMails: {
  31. // Czy ma odbierać przedmioty z poczty
  32. enabled: true
  33. }
  34. };
  35.  
  36. let opened = false, lastClick = 0, lastTalk = 0, stayCounter = 0;
  37.  
  38.  
  39. function sleep(ms) {
  40. return new Promise(resolve => setTimeout(resolve, ms));
  41. }
  42.  
  43. function calcFreeSpace() {
  44. return [0, 1, 2].reduce((total, curr) => total + g.bags[curr][0] - g.bags[curr][1], 0);
  45. }
  46.  
  47.  
  48. function isProperToSell(item) {
  49. const stat = parseItemStat(item.stat);
  50.  
  51. if (item.loc !== 'g' || item.st !== 0 || item.cl >= 15) {
  52. return false;
  53. }
  54. if (item.own !== hero.id || stat.soulbound === null || stat.permbound === null || stat.rarity !== 'unique') {
  55. return false;
  56. }
  57. if (stat.lvl && (stat.lvl < config.putAuction.minLvl || stat.lvl > config.putAuction.maxLvl)) {
  58. return false;
  59. }
  60. return true;
  61. }
  62.  
  63. function getItemsToSell() {
  64. return Object.values(g.item).filter(item => isProperToSell(item));
  65. }
  66.  
  67. function waitFor(condition, interval = 100, attempts = Infinity) {
  68. let times = 0;
  69.  
  70. const promise = (resolve, reject) => {
  71. if (condition()) {
  72. resolve();
  73. } else if (attempts === -1 || times < attempts) {
  74. times++;
  75. setTimeout(() => promise(resolve, reject), interval);
  76. } else {
  77. reject();
  78. }
  79. };
  80.  
  81. return new Promise(promise);
  82. }
  83.  
  84.  
  85. const main = async () => {
  86. await sleep(250);
  87.  
  88. if (map.name === 'Eder') {
  89. // Disable menogram if player has unique items, gold to send or mails to get
  90. if (
  91. (config.putAuction.enabled && getItemsToSell().length >= 1) ||
  92. (config.sendGold.enabled && hero.gold >= parsePrice(config.sendGold.minAmount) + 100) ||
  93. (config.getMails.enabled && hero.mails >= 1)
  94. )
  95. // Check if player has mails to get or gold to send
  96. if (
  97. (config.getMails.enabled && hero.mails >= 1) ||
  98. (config.sendGold.enabled && hero.gold > parsePrice(config.sendGold.minAmount) + 100)
  99. ) {
  100. // Go to mailbox
  101. if (!(hero.x === 36 && hero.y === 43)) {
  102. goTo(36, 43);
  103. return;
  104. }
  105. // Talk with mailbox
  106. if (!g.mails && Date.now() - lastTalk >= 350) {
  107. _g(`talk&id=17634`, () => lastTalk = Date.now());
  108. return;
  109. }
  110. }
  111.  
  112. // Check if mailbox is opened and player has mails or gold to send
  113. if (g.mails) {
  114. if (config.getMails.enabled && $('.getdel').length >= 1 && calcFreeSpace() > 0) {
  115. if (Date.now() - lastClick >= 350) {
  116. $('.getdel')[0].click();
  117. lastClick = Date.now();
  118. }
  119. return;
  120. }
  121. if (config.sendGold.enabled && hero.gold >= parsePrice(config.sendGold.minAmount) + 100) {
  122. if (Date.now() - lastTalk >= 350) {
  123. const amount = hero.gold - 100 - parsePrice(config.sendGold.saveGold);
  124. _g('mail&a=send&r=' + esc(config.sendGold.target) + '&gold=' + amount + '&iid=&msg=', () => lastTalk = Date.now());
  125. }
  126. return;
  127. }
  128. window.hideMails();
  129. return;
  130. }
  131.  
  132. // Go to auctioneer if player has unique items
  133. // Otherwise enable menogram and go to start map
  134. if (config.putAuction.enabled && getItemsToSell().length >= 1) {
  135. goTo(31, 50);
  136. } else {
  137. // Enable menogram
  138. // Go to 'Gildia Magów' gateway if current map is not a part of setup
  139. goTo(29, 0);
  140. }
  141. }
  142.  
  143. if (map.name === 'Eder') {
  144. // Go to 'Thuzal' gatewa
  145.  
  146. // Go to auctioneer
  147. // if (!(hero.x === 31 && hero.y === 50)) {
  148. // goTo(31, 50);
  149. // return;
  150. // }
  151.  
  152. if (!g.auctions && g.talk.id === 0) {
  153. _g('talk&id=44142');
  154. } else {
  155. if (!$('#auction-window .auction-window').length) {
  156. document.querySelector('#replies > li:nth-child(1)').click();
  157. return;
  158. }
  159.  
  160. if (!opened) {
  161. opened = true;
  162.  
  163. for (const item of getItemsToSell()) {
  164. let bidPrice = parsePrice(config.putAuction.bidPrice), buyPrice = parsePrice(config.putAuction.buyPrice);
  165. _g('ah&action=sell&item=' + item.id + '&price=' + bidPrice + '&buy_out=' + buyPrice + '&time=' + config.putAuction.time + '&is_featured=0');
  166. await sleep(950);
  167.  
  168. }
  169.  
  170. g.auctions.close();
  171.  
  172. }
  173. await sleep(800);
  174. goTo(29, 0)
  175. }
  176.  
  177. }
  178.  
  179. }
  180.  
  181. // Wait for game load
  182. waitFor(() => {
  183. return window.g && window.g.init > 4;
  184. }).then(() => {
  185. const old = window.parseInput;
  186.  
  187. window.parseInput = (d, callback, xhr) => {
  188. old(d, callback, xhr);
  189. main();
  190. }
  191. });
  192.  
Add Comment
Please, Sign In to add comment