Gladiatus Battle Bot

Expedition, dungeon, circus turma on colddown

当前为 2019-09-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Gladiatus Battle Bot
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Expedition, dungeon, circus turma on colddown
  6. // @author You
  7. // @match https://s*.gladiatus.gameforge.com/*
  8. // @grant none
  9. // @run-at document-start
  10.  
  11. // ==/UserScript==
  12.  
  13.  
  14. (function () {
  15. 'use strict';
  16. const ENEMY_NUMBER = 2;
  17. const EXPEDITION_NUMBER = 6;
  18. const ENABLE_EXPEDITIONS = true;
  19.  
  20. const HP_THRESHOLD = 15;
  21. const ENABLE_SMELTERY = false;
  22.  
  23. const ENABLE_TURMA = true;
  24. const ENABLE_DUNGEON = true;
  25. const TURMA_ENEMY = 5;
  26.  
  27. const ENABLE_EVENT = false;
  28. const EVENT_ENEMY = 3;
  29.  
  30. setInterval(main, 3000);
  31.  
  32. createGetResourcesToStore();
  33.  
  34.  
  35. function main() {
  36. console.log('Run Expedition Script');
  37. const d = document;
  38. var query = new URLSearchParams(window.location.search);
  39.  
  40. // VIEW
  41. const mod = query.get('mod');
  42. const submod = query.get('submod');
  43. const isDashboard = mod === 'overview';
  44. const isExpeditionView = mod === 'location';
  45. const isDungeonView = mod === 'dungeon';
  46. const isReportsView = mod === 'reports';
  47. const isArenaView = mod === 'arena';
  48. const isWorkView = mod === 'work';
  49. const isSmelteryView = mod === 'forge' && submod === 'smeltery';
  50. const isTurmaView = mod === 'arena' && submod === 'serverArena';
  51. const isEventView = mod === 'location' && submod === 'serverQuest';
  52.  
  53. // STATUS
  54. const hp = parseInt(d.getElementById('header_values_hp_percent').innerText);
  55. const expeditionReady = d.querySelectorAll('#cooldown_bar_expedition .cooldown_bar_fill_ready')[0];
  56. const dungeonReady = d.querySelectorAll('#cooldown_bar_dungeon .cooldown_bar_fill_ready')[0];
  57. const turmaReady = d.querySelectorAll('#cooldown_bar_ct .cooldown_bar_fill_ready')[0];
  58. const eventReady = findEventReady();
  59.  
  60.  
  61. // expedition battle
  62. if (hp > HP_THRESHOLD && expeditionReady) {
  63. sendRequest(
  64. 'get',
  65. 'ajax.php',
  66. `mod=location&submod=attack&location=${EXPEDITION_NUMBER}&stage=${ENEMY_NUMBER}&premium=0`,
  67. null);
  68. }
  69.  
  70. // dungeon battle
  71. if (ENABLE_EXPEDITIONS && isDungeonView && dungeonReady) {
  72. const enemies = d.getElementById('content').getElementsByTagName('img');
  73.  
  74. // start dungeon
  75. if (enemies.length === 0) {
  76. const dungeonBtns = d.getElementById('content').getElementsByTagName('input');
  77.  
  78. if(!dungeonBtns[1] || dungeonBtns[1].disabled) {
  79. dungeonBtns[0].click();
  80. } else {
  81. dungeonBtns[1].click();
  82. }
  83.  
  84. }
  85. //dungeon battle
  86. else {
  87. for (let i = 0; i < enemies.length; i++) {
  88. if (enemies[i].onclick) {
  89. enemies[i].click();
  90. break;
  91. }
  92. }
  93. }
  94. }
  95.  
  96. // circus turma battle
  97. if (isTurmaView && turmaReady) {
  98. const attackButton = document.getElementById('own3').getElementsByClassName('attack')[TURMA_ENEMY - 1];
  99. attackButton.click();
  100. }
  101.  
  102. // event battle
  103. if (ENABLE_EVENT && hp > HP_THRESHOLD && isEventView && eventReady) {
  104. const attackBtn = document.getElementsByClassName('expedition_button')[EVENT_ENEMY - 1];
  105. if (!attackBtn.disabled) {
  106. attackBtn.click();
  107. }
  108. }
  109.  
  110. // navigate to dungeon
  111. if (ENABLE_DUNGEON && dungeonReady && !isDungeonView) {
  112. const goToLink = d.querySelectorAll('#cooldown_bar_dungeon .cooldown_bar_link')[0];
  113. goToLink.click();
  114. }
  115.  
  116. // navigate to turma
  117. if (ENABLE_TURMA && turmaReady && !isTurmaView) {
  118. const battleLinkElem = d.querySelectorAll('#cooldown_bar_ct .cooldown_bar_link')[0];
  119. battleLinkElem.click();
  120. }
  121.  
  122. // navigate to event
  123. if (ENABLE_EVENT && eventReady && !isEventView) {
  124. const banner = document.getElementById('banner_event_link');
  125. banner.click();
  126. }
  127.  
  128. //Smeltery
  129. if (!isSmelteryView && ENABLE_SMELTERY) {
  130. d.getElementById('submenu1').getElementsByTagName('a')[12].click();
  131. }
  132.  
  133. if (isSmelteryView && ENABLE_SMELTERY) {
  134. const forges = d.getElementsByClassName('forge_finished-succeeded');
  135.  
  136. for (let i = 0; i < forges.length; i++) {
  137. if (!forges[i].hasClass('tabActive')) {
  138. forges[i].click();
  139. }
  140.  
  141. setTimeout(function () {
  142. const elem = d.getElementById('forge_lootbox');
  143. elem && elem.click();
  144. }, 500);
  145. }
  146. }
  147. }
  148.  
  149. function createGetResourcesToStore() {
  150. const intervalId = setInterval(function () {
  151. const gcaBar = document.getElementById('gca_shortcuts_bar');
  152. if (!gcaBar) {
  153. return
  154. }
  155.  
  156. const element = document.createElement('div');
  157. element.className = 'icon-out';
  158.  
  159. const iconElement = document.createElement('a');
  160. iconElement.className = 'icon box-icon';
  161. iconElement.setAttribute('title', 'Store packages');
  162.  
  163. element.appendChild(iconElement);
  164. element.addEventListener('click', function () {
  165. var content = document.getElementById('content');
  166. var link = 'ajax.php?mod=forge&submod=storageIn';
  167. var params = 'inventory=1&packages=1&sell=1';
  168. sendAjax(content, link, params, function () {
  169. gca_notifications.success('Packages were stored');
  170. });
  171. });
  172.  
  173. gcaBar.appendChild(element);
  174. clearInterval(intervalId);
  175. }, 100);
  176. }
  177.  
  178. function findEventReady() {
  179. const tries = document.querySelectorAll('#ServerQuestTime span')[0] || {};
  180. return parseInt(tries.innerHTML) > 0;
  181. }
  182. }
  183. )();