Advertisement
affekk

Untitled

Oct 1st, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.02 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Wystawianie itemków
  3. // @version 1.0
  4. // @author yetrr#4049
  5. // @match https://*.margonem.pl/*
  6. // @require https://pastebin.com/raw/Vs5sxakw
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. // Sekcja konfiguracji
  11. const config = {
  12. putAuction: {
  13. // Czy wystawianie na aukcje ma być włączone
  14. enabled: true,
  15. // Za ile można licytować
  16. // Wpisz '', jeśli ma nie wystawiać na licytację
  17. bidPrice: '20m',
  18. // Za ile ma wystawić
  19. // Wpisz '', jeśli ma nie wystawiać na kup teraz
  20. buyPrice: '500m',
  21. // Na ile wystawić (czas w godzinach)
  22. time: 2,
  23. // Minimalny poziom przemiotu do wystawienia
  24. minLvl: 100,
  25. // Maksymalny poziom przedmiotu do wystawienia
  26. maxLvl: 120
  27. },
  28. sendGold: {
  29. // Czy wysyłanie golda ma być włączone
  30. enabled: true,
  31. // Minimalna ilość złota, od której ma wysyłać
  32. minAmount: '3m',
  33. // Ilość złota, którą ma zostawiać
  34. saveGold: '500k',
  35. // Na jaki nick ma wysyłać
  36. target: 'tester'
  37. },
  38. getMails: {
  39. // Czy ma odbierać przedmioty z poczty
  40. enabled: true
  41. }
  42. };
  43.  
  44. let opened = false,
  45. talked = false,
  46. lastClick = 0,
  47. lastTalk = 0;
  48.  
  49. const options = {
  50. 1: 0, 2: 1,
  51. 9: 2, 35: 3,
  52. 33: 4, 574: 5,
  53. 579: 6, 114: 7,
  54. };
  55.  
  56. function sleep(ms) {
  57. return new Promise(resolve => setTimeout(resolve, ms));
  58. }
  59.  
  60. function calcFreeSpace() {
  61. return [0, 1, 2].reduce((total, curr) => total + g.bags[curr][0] - g.bags[curr][1], 0);
  62. }
  63.  
  64. function checkMenogramBookmark() {
  65. if ($(".ui-draggable:contains('Aktualna wersja bota')").length === 0) {
  66. $("#lagmeter").click();
  67. }
  68. if ($("button:contains('Relog')").css('display') === 'none') {
  69. $("button:contains('Exp/e2')").click();
  70. }
  71. }
  72.  
  73. function getMenogramStatus() {
  74. checkMenogramBookmark();
  75. return $("label:contains('Stan') > label > input:checked").length === 1;
  76. }
  77.  
  78. function toggleMenogramStatus() {
  79. $("label:contains('Stan') > label > input").click();
  80. }
  81.  
  82. async function getStartMaps() {
  83. checkMenogramBookmark();
  84.  
  85. const element = $("label:contains('ID map po których ma wracać bot') > textarea");
  86.  
  87. if (element.length === 0) {
  88. await sleep(100);
  89. return getStartMaps();
  90. }
  91.  
  92. return element.val().split(',').map(it => Number(it));
  93. }
  94.  
  95. function countUniqueItems() {
  96. return Object.values(g.item)
  97. .filter(item => item.stat.includes('unique') && !item.stat.includes('permbound'))
  98. .filter(item => item.loc === 'g' && item.st === 0 && item.cl < 15)
  99. .filter(item => Number(parseItemStat(item.stat).lvl) >= config.putAuction.minLvl && Number(parseItemStat(item.stat).lvl) <= config.putAuction.maxLvl)
  100. .length;
  101. }
  102.  
  103. function waitFor(condition, interval = 100, attempts = Infinity) {
  104. let times = 0;
  105.  
  106. const promise = (resolve, reject) => {
  107. if (condition()) {
  108. resolve();
  109. } else if (attempts === -1 || times < attempts) {
  110. times++;
  111. setTimeout(() => promise(resolve, reject), interval);
  112. } else {
  113. reject();
  114. }
  115. };
  116.  
  117. return new Promise(promise);
  118. }
  119.  
  120. const main = async () => {
  121. await sleep(250);
  122.  
  123. if (map.name === 'Thuzal') {
  124. // Disable menogram if player has unique items, gold to send or mails to get
  125. if (getMenogramStatus() && (
  126. (config.putAuction.enabled && countUniqueItems() >= 1) ||
  127. (config.sendGold.enabled && hero.gold >= parsePrice(config.sendGold.minAmount) + 100) ||
  128. (config.getMails.enabled && hero.mails >= 1)
  129. )) {
  130. toggleMenogramStatus();
  131. }
  132.  
  133. // Check if player has mails to get or gold to send
  134. if (
  135. (config.getMails.enabled && hero.mails >= 1) ||
  136. (config.sendGold.enabled && hero.gold > parsePrice(config.sendGold.minAmount) + 100)
  137. ) {
  138. // Go to mailbox
  139. if (!(hero.x === 72 && hero.y === 19)) {
  140. goTo(72, 19);
  141. return;
  142. }
  143. // Talk with mailbox
  144. if (!g.mails && Date.now() - lastTalk >= 350) {
  145. _g(`talk&id=58930`, () => lastTalk = Date.now());
  146. return;
  147. }
  148. }
  149.  
  150. // Check if mailbox is opened and player has mails or gold to send
  151. if (g.mails) {
  152. if (config.getMails.enabled && $('.getdel').length >= 1 && calcFreeSpace() > 0) {
  153. if (Date.now() - lastClick >= 350) {
  154. $('.getdel')[0].click();
  155. lastClick = Date.now();
  156. }
  157. return;
  158. }
  159. if (config.sendGold.enabled && hero.gold >= parsePrice(config.sendGold.minAmount) + 100) {
  160. if (Date.now() - lastTalk >= 350) {
  161. const amount = hero.gold - 100 - parsePrice(config.sendGold.saveGold);
  162. _g('mail&a=send&r=' + config.sendGold.target + '&gold=' + amount + '&iid=&msg=', () => lastTalk = Date.now());
  163. }
  164. return;
  165. }
  166. window.hideMails();
  167. return;
  168. }
  169.  
  170. // Go to auctioneer if player has unique items
  171. // Otherwise enable menogram and go to start map
  172. if (config.putAuction.enabled && countUniqueItems() >= 1) {
  173. goTo(77, 26);
  174. } else {
  175. // Enable menogram
  176. if (!getMenogramStatus()) {
  177. toggleMenogramStatus();
  178. }
  179. // Go to 'Gildia Magów' gateway if current map is not a part of setup
  180. if ((await getStartMaps()).indexOf(114) === -1) {
  181. goTo(66, 18);
  182. }
  183. }
  184. }
  185.  
  186. if (map.name === 'Ratusz Thuzal') {
  187. // Go to 'Thuzal' gateway
  188. if (countUniqueItems() === 0) {
  189. goTo(20, 5);
  190. return;
  191. }
  192.  
  193. // Go to auctioneer
  194. if (!(hero.x === 20 && hero.y === 10)) {
  195. goTo(20, 10);
  196. return;
  197. }
  198.  
  199. if (!g.talk.id && !talked) {
  200. _g('talk&id=60088', () => talked = true);
  201. } else {
  202. if ($('#auctions').css('display') !== 'block') {
  203. document.querySelector('#replies > li:nth-child(1)').click();
  204. return;
  205. }
  206.  
  207. if (!opened) {
  208. opened = true;
  209.  
  210. for (const item of Object.values(g.item)) {
  211. if (hero.gold < 1060) {
  212. message('Masz za mało złota!');
  213. break;
  214. } else if (item.loc === 'g' && item.st === 0 && item.cl < 15 && item.own === hero.id
  215. && !item.stat.includes('permbound')
  216. && item.stat.includes('unique')) {
  217. _g('ah&sell=' + item.id + '&price=' + parsePrice(config.putAuction.bidPrice) + '&bo=' + parsePrice(config.putAuction.buyPrice) + '&time=' + config.putAuction.time);
  218. await sleep(250);
  219. }
  220. }
  221. window.auctionsHide();
  222. }
  223. }
  224. }
  225.  
  226. if (map.name === 'Gildia Magów') {
  227. // Go to teleport
  228. if (!(hero.x === 17 && hero.y === 14)) {
  229. goTo(17, 14);
  230. return;
  231. }
  232.  
  233. // Talk with teleport
  234. if (!g.talk.id && Date.now() - lastTalk >= 350) {
  235. _g('talk&id=59861', () => lastTalk = Date.now());
  236. } else if ($('#dialog').css('display') === 'block') {
  237. const mapId = (await getStartMaps())[0];
  238. $(`#dlgin li:eq(${options[mapId]})`).click();
  239. }
  240. }
  241. }
  242.  
  243. // Wait for game load
  244. waitFor(() => {
  245. return window.g && window.g.init > 4;
  246. }).then(() => {
  247. const old = window.parseInput;
  248.  
  249. window.parseInput = (d, callback, xhr) => {
  250. old(d, callback, xhr);
  251. main();
  252. }
  253. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement