Advertisement
Nolifeq

Untitled

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