Donnabot's GOTA_Extender_Auxiliary

GOTA_Extender_Auxiliary to go with my fork of GOTA_Extender

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/7490/35115/Donnabot%27s%20GOTA_Extender_Auxiliary.js

  1. var extender = {
  2. command: function (name, args) {
  3. var cmd = { name: name, args: args };
  4. $("textarea#observable").attr("command", JSON.stringify(cmd));
  5. },
  6. lastcommand: function () {
  7. var observable = $("textarea#observable");
  8. var lcmd = observable.attr("command");
  9. observable.val(lcmd);
  10. return lcmd;
  11. },
  12. option: function (option, val) {
  13. if (typeof option == "string") {
  14. this.command("option", [option, val]);
  15. } else {
  16. error("Please specify name and value as parameters.", "COMMAND");
  17. }
  18. },
  19. collect: function(){
  20. this.command("collect");
  21. }
  22. };
  23. //
  24. //var productionQueue = [];
  25. //function attemptProduction(bSymbol) {
  26. //
  27. // if (!productionQueue || productionQueue.length == 0) {
  28. // log('Attempted production, but queue was missing or empty. Exiting...', "PRODUCTION");
  29. // return;
  30. // }
  31. //
  32. // if (typeof bSymbol != "undefined") {
  33. //
  34. // // Check this building for production
  35. // var b = buildingBySymbol(bSymbol);
  36. //
  37. // if (buildingProducing(b)) {
  38. // log("Building " + b.symbol + " is busy.", "PRODUCTION");
  39. // return;
  40. // }
  41. //
  42. // if (buildingFinished(b)) {
  43. // log("Building " + b.symbol + " finished production.", "PRODUCTION");
  44. //
  45. // doFinishProduction(b.item_id, function() {
  46. // setTimeout(function() {
  47. // attemptProduction(b.symbol);
  48. // }, extender_queueDelay * 1000);
  49. // });
  50. //
  51. // return;
  52. // }
  53. //
  54. // var element = getElement(b.symbol);
  55. // if (element) {
  56. // executeElement(element);
  57. // return;
  58. // }
  59. // } else {
  60. //
  61. // for (var i = 0; i < userContext.buildingsData.length; i++) {
  62. // var b = userContext.buildingsData[i];
  63. //
  64. // if (buildingProducing(b)) {
  65. // log("Building " + b.symbol + " is busy.", "PRODUCTION");
  66. // continue;
  67. // }
  68. //
  69. // if (buildingFinished(b)) {
  70. // log("Building " + b.symbol + " finished production.", "PRODUCTION");
  71. // doFinishProduction(b.item_id, function() {
  72. // setTimeout(function() {
  73. // attemptProduction(b.symbol);
  74. // }, extender_queueDelay * 1000);
  75. // });
  76. //
  77. // return;
  78. // }
  79. //
  80. // var element = getElement(b.symbol);
  81. // if (element) {
  82. // executeElement(element, function () {
  83. // attemptProduction();
  84. // });
  85. //
  86. // return;
  87. // }
  88. // }
  89. // }
  90. //};
  91. //
  92. //function getElement(buildingSymbol) {
  93. // if (!productionQueue || productionQueue.length == 0) {
  94. // log('Attempted to extract item from queue, but the production queue was missing or empty. Exiting...', "PRODUCTION");
  95. // return null;
  96. // }
  97. //
  98. // var element;
  99. //
  100. // for (var i = 0; i < productionQueue.length; i++) {
  101. //
  102. // if (productionQueue[i].activeBuildingPanel == buildingSymbol) {
  103. // element = productionQueue[i];
  104. // break;
  105. // }
  106. // }
  107. //
  108. // if (!element) {
  109. // log('No elements enqueued for building ' + buildingSymbol + '. Array size: ' + productionQueue.length, "PRODUCTION");
  110. // return null;
  111. // }
  112. //
  113. // return element;
  114. //};
  115. //
  116. //function executeElement(element, callback) {
  117. //
  118. // var index = productionQueue.indexOf(element);
  119. // log('Production of element ' + element.name + ' : ' + element.type + ' with index ' + index + ' initiated.', "PRODUCTION");
  120. //
  121. // if (element.type == "item") {
  122. // userContext.recipeData = element.recipeData;
  123. // userContext.activeBuildingPanel = element.activeBuildingPanel;
  124. //
  125. // doProduction(element.outputSymbol, element.recipeCategory, null, null, element.recipeName, callback);
  126. // productionQueue.splice(index, 1);
  127. // extender.save("productionQueue");
  128. //
  129. // log('Production details: ' + element.name + ' at ' + element.activeBuildingPanel + ', ' + element.outputSymbol + ', ' + element.recipeCategory + ', ' + element.recipeName + ';', "PRODUCTION");
  130. // } else {
  131. //
  132. // var buildingId = buildingBySymbol(element.activeBuildingPanel).id;
  133. //
  134. // applySelectedUpgrade({ building_id: buildingId, id: element.upgradeId, gold: 0, silver: 0 }, null, callback);
  135. // productionQueue.splice(index, 1);
  136. // extender.save("productionQueue");
  137. //
  138. // log('Production details: ' + element.name + ' : ' + element.type + ' at ' + element.activeBuildingPanel + ', ' + element.symbol + ';', "PRODUCTION");
  139. //
  140. // }
  141. //};
  142.  
  143. function buildingFinished(b) {
  144.  
  145. // DO NOT call this function for the keep: it has neither build_remaining nor producing_archetype_id
  146.  
  147. // When a building finished either producing or bonus archetype id's should be present along with
  148. // no build time remaining to safely determine that this building has produced the item (luck or not)
  149. // but has not finalized the production yet (that's clicking the finish button)
  150. // Note that upgrades also enlist with a producing_archetype_id here, so they behave similarly
  151. return (b.producing_archetype_id != void 0 || b.bonus_archetype_id != void 0) && b.build_remaining == void 0;
  152. }
  153.  
  154. function buildingProducing(b) {
  155.  
  156. // DO NOT call this function for the keep: it has neither build_remaining nor producing_archetype_id
  157.  
  158. // Luck-based recipes do not assign producing_archetype_id property
  159. // for all others this returns the remaining build
  160. //return b.producing_archetype_id && b.build_remaining;
  161.  
  162. // Simple and short, if this property is present and the value
  163. // is a positive number, then the building is still in production
  164. return b.build_remaining != void 0 && b.build_remaining > 0;
  165. }
  166.  
  167. function updateBuildingTimer(b){
  168. }
  169.  
  170. var bruteForceTimeout;
  171. function bruteForce(enabled, times) {
  172.  
  173. if (brutingImmediateTermination) {
  174. bruteForceTimeout = clearTimeout(bruteForceTimeout);
  175.  
  176. msg = "Bruting terminated immediately.";
  177. log(msg, "BRUTING");
  178. inform(msg);
  179. return;
  180. }
  181.  
  182. var msg;
  183. var container = $("#bruteBtn");
  184. if (!container || container.length == 0) {
  185. container = $(".challengerewardbox .rewarditem:last");
  186. }
  187.  
  188. if (!container || container.length == 0) {
  189. container = $(".challengerewards .challengerewarditems:first");
  190. }
  191.  
  192. if (!container || container.length == 0) {
  193. msg = "Cannot find appropriate container for messaging!";
  194. warn(msg);
  195. }
  196.  
  197. if (typeof enabled == "boolean" && !enabled) {
  198. bruteForceTimeout = clearTimeout(bruteForceTimeout);
  199.  
  200. msg = "Bruting terminated.";
  201. log(msg, "BRUTING");
  202.  
  203. // console.debug("Debuging message delivery: is there a container? " + (container) + ", " +
  204. // "what's his length: " + container.length + ", append message? " + (container && container.length > 0) + ", " +
  205. // "and what's the message: " + msg);
  206.  
  207. if (container.hasClass("btnwrap btnmed")) {
  208. container.find("a").text("Done!");
  209. }
  210.  
  211. container.after("<br />" + msg);
  212.  
  213. if (times === "all") {
  214. bruteSendAll();
  215. }
  216.  
  217. return;
  218. }
  219.  
  220. // Do not run if bruting is disabled (but can be viewed)
  221. if (extender_bruteWounds && extender_bruteWounds == 0) {
  222.  
  223. msg = "Disabled. Please set a positive number of max wounds from options to continue.";
  224. warn(msg, "BRUTING");
  225.  
  226. // console.debug("Debuging message delivery: is there a container? " + (container) + ", " +
  227. // "what's his length: " + container.length + ", append message? " + (container && container.length > 0) + ", " +
  228. // "and what's the message: " + msg);
  229.  
  230. container.after("<br />" + msg);
  231.  
  232. bruteForce(false, times);
  233. return;
  234. }
  235.  
  236. var s = userContext.setSwornSword;
  237.  
  238. //var sAsString = JSON.stringify(s);
  239. //log("GETTING S INFO" + sAsString + ".", "BRUTING");
  240.  
  241. if (!s) {
  242. msg = "Failed, no sworn sword set.";
  243. error(msg, "BRUTING");
  244.  
  245. container.after("<br />" + msg);
  246. bruteForce(false, times);
  247. return;
  248. }
  249.  
  250. // console.debug("Debuging sworn sword condition: s.damage: " + s.damage + ", " +
  251. // "extender_bruteWounds: " + extender_bruteWounds + ", do bruting? " + (s.damage < extender_bruteWounds));
  252.  
  253. if (s.damage < extender_bruteWounds) {
  254.  
  255. resolveModifier(s);
  256.  
  257. var attack =
  258. extender_sendAllAction === "selected" && !(!userContext.currentActionLabel)
  259. ? userContext.currentActionLabel : s.modifier;
  260.  
  261. // console.debug("Attack with: " + attack);
  262. if (times == "once") {
  263. doAdventure("", attack, false, function (failure) {
  264. bruteForce(false, times);
  265. });
  266. } else {
  267. doAdventure("", attack, false, function (failure) {
  268. bruteForce(!failure, times);
  269. });
  270. }
  271. var upgradetimes = s.upgrade_points;
  272. var lastdoness = sessionStorage.get("lastdoness","0");
  273. while(upgradetimes > 0 && s.id != lastdoness){
  274. if(extender_existTrain == "mod"){
  275. doTrain(s.modifier, s.id, s.full_name);
  276. msg = "Training " + s.full_name + " in " + s.modifier + ". "+ upgradetimes +" points to go.";
  277. }else{
  278. var max = Math.max(s.calc_battle, s.calc_trade, s.calc_intrigue);
  279. if (max == s.calc_intrigue) {
  280. var StattoTrain="intrigue";
  281. } else if (max == s.calc_trade) {
  282. var StattoTrain="trade";
  283. } else {
  284. var StattoTrain="battle";
  285. }
  286. doTrain(StattoTrain, s.id, s.full_name);
  287. msg = "Training " + s.full_name + " in " + StattoTrain + ". " + upgradetimes +" points to go.";
  288. }
  289. log(msg, "TRAINING");
  290. container.after("<br />" + msg);
  291. upgradetimes--;
  292. }
  293. sessionStorage.set("lastdoness",s.id);
  294.  
  295.  
  296. return;
  297. }
  298.  
  299. if (times === "all" || extender_bruteSwitchOff) {
  300.  
  301. msg = "Sworn sword recieved " + extender_bruteWounds + " wounds! Brute timer will self terminate.";
  302. warn(msg, "BRUTING");
  303.  
  304. // console.debug("Debuging message delivery: is there a container? " + (container) + ", " +
  305. // "what's his length: " + container.length + ", append message? " + (container && container.length > 0) + ", " +
  306. // "and what's the message: " + msg);
  307.  
  308. container.after("<br />" + msg);
  309.  
  310. bruteForce(false, times);
  311.  
  312. } else {
  313.  
  314. // Add a minute to the cooldown, and then multiply by wounds
  315. var interval = extender_bruteWounds * (s.damage_cooldown + 60);
  316. msg = "Sworn sword recieved " + extender_bruteWounds + " wounds! " +
  317. "Brute timer will self adjust. Wait " + extender_bruteWounds + " * (" + s.damage_cooldown + " + 60) = " + interval + " seconds.";
  318.  
  319. warn(msg, "BRUTING");
  320.  
  321. bruteForceTimeout = setTimeout(function () {
  322. bruteForce(true, times);
  323. }, interval * 1000);
  324.  
  325. // console.debug("Debuging message delivery: is there a container? " + (container) + ", " +
  326. // "what's his length: " + container.length + ", append message? " + (container && container.length > 0) + ", " +
  327. // "and what's the message: " + msg);
  328.  
  329. container.after("<br />" + msg);
  330. }
  331. };
  332.  
  333. function bruteSendAll() {
  334. var sw = getSwornSwords(extender_sendAllAction);
  335. console.debug("Sworn swords retrieved successfully...");
  336.  
  337. for (var i = 0; i < sw.length; i++) {
  338. var ss = sw[i];
  339.  
  340. if (typeof ss.not_on_adventure == "boolean" && ss.not_on_adventure)
  341. continue;
  342.  
  343. if (ss.cooldown > 0 || ss.damage >= extender_bruteWounds)
  344. continue;
  345.  
  346. console.debug("Sending: " + ss.full_name);
  347.  
  348. setSwornSword(ss.id);
  349. bruteForce(true, "all");
  350. return;
  351. }
  352.  
  353. inform("All sworn swords have been bruted to maximum wounds.<br>Action: " + extender_sendAllAction);
  354.  
  355. }
  356.  
  357. var brutingImmediateTermination = false;
  358. $(document).on("keyup", function (e) {
  359. if (e.keyCode == 27) {
  360. e.preventDefault();
  361. e.stopPropagation();
  362.  
  363. brutingImmediateTermination = true;
  364. log("Attempting immediate bruting termination.");
  365. }
  366. });
  367.  
  368. function increment(me) {
  369. var opt = $(me);
  370.  
  371. var min = parseInt(opt.attr("min"));
  372. var max = parseInt(opt.attr("max"));
  373. var step = parseInt(opt.attr("step"));
  374. var val = parseInt(opt.text());
  375.  
  376. if (isNaN(min) || isNaN(max) || isNaN(step) || isNaN(val)) {
  377. error("Parsing of attributes failed!", "number option");
  378. return;
  379. }
  380.  
  381. var newVal = val + step > max ? min : val + step;
  382. opt.text(newVal);
  383. };
  384.  
  385. function check(me) {
  386. $(me).toggleClass('checked');
  387. };
  388.  
  389. function bruteSwitchToggle(me) {
  390. var bSwitch = $(me).find("a.btngold");
  391. bSwitch.text() == "switch off"
  392. ? bSwitch.text("adjust")
  393. : bSwitch.text("switch off");
  394. };
  395.  
  396. function inputIncrement(me) {
  397. var input = $(me).parent().find("input[name='quantity']");
  398. if (!input || input.length == 0) {
  399. return;
  400. }
  401.  
  402. var v = parseInt(input.val());
  403. var max = parseInt(input.attr("maxlength"));
  404. if (isNaN(v) || isNaN(max)) {
  405. return;
  406. }
  407.  
  408. if (me.id == "excountup") {
  409. (max == 3 ? max = 999 : max = 99);
  410. (v + 1 > max ? v = max : v = v + 1);
  411. } else if (me.id == "excountdown") {
  412. (v - 1 < 0 ? v = 0 : v = v - 1);
  413. }
  414.  
  415. input.val(v);
  416. }
  417.  
  418. function sort(arr) {
  419. if (typeof arr == "undefined") {
  420. arr = playerInventory;
  421. }
  422.  
  423. if (!(arr instanceof Array)) {
  424. error("Not an array! Sorting failed.");
  425. return arr;
  426. }
  427. // console.debug("Sorting of array initiated, check parameters: boons count: " + boons.length + ", " +
  428. // "sorting property: " + extender_boonsSortBy);
  429.  
  430. arr.sort(function (a, b) {
  431. return b[extender_boonsSortBy2] - a[extender_boonsSortBy2];
  432. });
  433.  
  434. arr.sort(function (a, b) {
  435. return b[extender_boonsSortBy] - a[extender_boonsSortBy];
  436. });
  437.  
  438. log("Array sorted by " + extender_boonsSortBy + " and then by " + extender_boonsSortBy2 + " successfully.", "PAGE");
  439. return arr;
  440.  
  441. }
  442.  
  443. function sortShop(arr) {
  444. if (typeof arr == "undefined" || !(arr instanceof Array)) {
  445. error("Not an array. Please pass an array to be sorted.");
  446. return arr;
  447. }
  448.  
  449. //console.debug("Sorting of array initiated, check array count: " + arr.length);
  450.  
  451. arr.sort(function(a, b) {
  452.  
  453. //console.debug("Init first sorting, condition 1, properties exist: ", a.hasOwnProperty(extender_shopSortBy2), b.hasOwnProperty(extender_shopSortBy2));
  454. if (!a.hasOwnProperty(extender_shopSortBy2) || !b.hasOwnProperty(extender_shopSortBy2)) {
  455. return false;
  456. }
  457.  
  458. var aVal = a[extender_shopSortBy2];
  459. var bVal = b[extender_shopSortBy2];
  460.  
  461. //console.debug("Logging property values: ", aVal, bVal);
  462.  
  463. if (typeof aVal != "number" || typeof bVal != "number") {
  464.  
  465. //console.debug("Values need parsing...");
  466.  
  467. aVal = parseInt(aVal);
  468. bVal = parseInt(bVal);
  469.  
  470. //console.debug("Parsed values: ", aVal, bVal);
  471. if (isNaN(aVal) || isNaN(bVal)) {
  472. return false;
  473. }
  474. }
  475.  
  476. //console.debug("Sorting descending...");
  477. return bVal - aVal;
  478. });
  479.  
  480. arr.sort(function (a, b) {
  481.  
  482. //console.debug("Init second sorting, condition 1, properties exist: ", a.hasOwnProperty(extender_shopSortBy2), b.hasOwnProperty(extender_shopSortBy2));
  483. if (!a.hasOwnProperty(extender_shopSortBy) || !b.hasOwnProperty(extender_shopSortBy)) {
  484. return false;
  485. }
  486. var aVal = a[extender_shopSortBy];
  487. var bVal = b[extender_shopSortBy];
  488.  
  489. //console.debug("Logging property values: ", aVal, bVal);
  490.  
  491. if (typeof aVal != "number" || typeof bVal != "number") {
  492.  
  493. //console.debug("Values need parsing...");
  494.  
  495. aVal = parseInt(aVal);
  496. bVal = parseInt(bVal);
  497.  
  498. //console.debug("Parsed values: ", aVal, bVal);
  499. if (isNaN(aVal) || isNaN(bVal)) {
  500. return false;
  501. }
  502. }
  503.  
  504. //console.debug("Sorting descending...");
  505. return bVal - aVal;
  506. });
  507.  
  508. // Array will always be sorted by gold, descending
  509. arr.sort(function (a, b) {
  510. return parseInt(a["price_perk_points"]) - parseInt(b["price_perk_points"]);
  511. });
  512.  
  513. //console.debug("Sorted by gold: ");
  514.  
  515. //arr.forEach(function (element) {
  516. // console.debug(element["price_perk_points"]);
  517. //});
  518.  
  519. log("Array sorted by " + extender_shopSortBy + " and then by " + extender_shopSortBy2 + " successfully.", "PAGE");
  520. return arr;
  521.  
  522. }
  523.  
  524. function formatStats(battle, trade, intrigue, level) {
  525. return '<div class="exstatbox">' +
  526. '<div id="plevel" class="statitem">' +
  527. '<div><span></span>' +
  528. '</div><var>' + level + '</var></div>' +
  529. '<div id="battle" class="statitem">' +
  530. '<div><span></span>' +
  531. '</div><var class="battle_val" id="battle_val">' + battle + '</var></div>' +
  532. '<div id="trade" class="statitem">' +
  533. '<div><span></span>' +
  534. '</div><var class="trade_val" id="trade_val">' + trade + '</var></div>' +
  535. '<div id="intrigue" class="statitem">' +
  536. '<div><span></span></div>' +
  537. '<var class="intrigue_val" id="intrigue_val">' + intrigue + '</var></div>' +
  538. '</div>';
  539. }
  540.  
  541. function getSwornSwords(filter, garrison_region, garrison_subregion) {
  542. var ss = [];
  543. var pi = playerInventory;
  544.  
  545. for (var i = 0; i < pi.length; i++) {
  546. var s = pi[i];
  547.  
  548. if (s.slot !== "Sworn Sword")
  549. continue;
  550.  
  551. if (!s.modifier) {
  552. resolveModifier(s);
  553. }
  554.  
  555. if (typeof filter == "number" && !isNaN(filter) && s.id === filter) {
  556. return s;
  557. }
  558.  
  559. if (typeof filter == "string" && !isNaN(parseInt(filter)) && s.id === parseInt(filter)) {
  560. return s;
  561. }
  562.  
  563. if (typeof garrison_region != "undefined" && typeof garrison_subregion != "undefined" &&
  564. !isNaN(garrison_region) && !isNaN(garrison_subregion) && !checkGarrison(s, garrison_region, garrison_subregion))
  565. continue;
  566.  
  567. if (typeof filter == "string") {
  568.  
  569. if (filter == "all" || filter == "selected") {
  570. ss.push(s);
  571. continue;
  572.  
  573. } else if (filter == "none"){
  574. continue;
  575. }
  576.  
  577. var friendlyActions = ["aid", "barter", "bribe"];
  578. var hostileActions = ["fight", "harass", "spy", "sabotage", "steal", "hoodwink"];
  579.  
  580. var battleActions = ["fight", "harass", "aid"];
  581. var tradeActions = ["barter", "hoodwink", "bribe"];
  582. var intrigueActions = ["spy", "sabotage", "steal"];
  583.  
  584. //if ((friendlyActions.indexOf(filter) > -1 || hostileActions.indexOf(filter) > -1) && s.modifier != filter) {
  585. // continue;
  586. //}
  587.  
  588. switch (filter) {
  589. case "battle":
  590. {
  591. if (battleActions.indexOf(s.modifier) == -1)
  592. continue;
  593. else
  594. break;
  595. }
  596. case "trade":
  597. {
  598. if (tradeActions.indexOf(s.modifier) == -1)
  599. continue;
  600. else
  601. break;
  602. }
  603. case "intrigue":
  604. {
  605. if (intrigueActions.indexOf(s.modifier) == -1)
  606. continue;
  607. else
  608. break;
  609. }
  610. case "friendly":
  611. {
  612. if (friendlyActions.indexOf(s.modifier) == -1)
  613. continue;
  614. else
  615. break;
  616. }
  617. case "hostile":
  618. {
  619. if (hostileActions.indexOf(s.modifier) == -1)
  620. continue;
  621. else
  622. break;
  623. }
  624. default:
  625. {
  626. if (s.modifier != filter)
  627. continue;
  628. else
  629. break;
  630. }
  631. }
  632. }
  633.  
  634. ss.push(s);
  635. }
  636.  
  637. return ss;
  638. }
  639.  
  640. function checkGarrison(s, region, subregion) {
  641. if (typeof s.garrison_region == "undefined" || typeof s.garrison_subregion == "undefined" ||
  642. isNaN(s.garrison_region) && isNaN(s.garrison_subregion)) {
  643. return false;
  644. }
  645.  
  646. if (s.garrison_region != region || s.garrison_subregion != subregion) {
  647. return false;
  648. }
  649.  
  650. return true;
  651. }
  652.  
  653. function setSwornSword(param) {
  654. if (typeof param == "undefined") {
  655. error("The function requires a sworn sword id as parameter.")
  656. return;
  657. }
  658. if (typeof param == "number") {
  659. var s = extractItemById(playerInventory, param);
  660. s && (userContext.setSwornSword = s);
  661. } else if (typeof param == "string") {
  662. var s = extractItemById(playerInventory, parseInt(param));
  663. s && (userContext.setSwornSword = s);
  664. } else if (typeof param == "object") {
  665. userContext.setSwornSword = param;
  666. }
  667. }
  668.  
  669. function checkCommandPoints() {
  670. if(!userContext || !userContext.playerData || !userContext.playerData.stat)
  671. return false;
  672.  
  673. var commandPoints = userContext.playerData.stat.command - userContext.playerData.stat.current_command;
  674.  
  675. log("Debugging check command points: command points: " + commandPoints + ", " +
  676. "continue then? " + (!isNaN(commandPoints) && commandPoints > 0));
  677.  
  678. return !isNaN(commandPoints) && commandPoints > 0;
  679. }
  680. function adventureSendAll(adventure, swornswords) {
  681.  
  682. if (extender_sendAllAction === "none") {
  683. inform("This function is disabled. Please enable it from options.");
  684. return;
  685. }
  686.  
  687. if(!checkCommandPoints()){
  688. inform("Not enough command points. <br>Action cannot execute.");
  689. return;
  690. }
  691.  
  692. if (typeof swornswords == "undefined" || !(swornswords instanceof window.Array)) {
  693. error("An array should be passed to the function. Sending failed.");
  694. return;
  695. }
  696.  
  697. if (typeof adventure != "string") {
  698. error("Adventure should be passed as a string. Sending failed.");
  699. return;
  700. }
  701.  
  702. if (swornswords.length == 0) {
  703. inform('All sworn swords send on ' + adventure + '.<br>Action: ' + extender_sendAllAction);
  704. return;
  705. }
  706.  
  707. var s = swornswords.pop();
  708.  
  709. log("Debuging send all: swornswords: " + swornswords.length + ", " +
  710. "current: " + s.full_name + ", " +
  711. "cooldown: " + s.cooldown + ", " +
  712. "damage: " + s.damage + ", " +
  713. "send? " + !(s.cooldown > 0 || s.damage >= extender_bruteWounds));
  714.  
  715. if(s.cooldown > 0 || s.damage >= extender_bruteWounds) {
  716. adventureSendAll(adventure, swornswords);
  717. return;
  718. }
  719.  
  720. setSwornSword(s.id);
  721.  
  722. if (!s.modifier) {
  723. resolveModifier(s);
  724. }
  725.  
  726. var attack =
  727. extender_sendAllAction === "selected" && !(!userContext.currentActionLabel)
  728. ? userContext.currentActionLabel : s.modifier;
  729.  
  730. doAdventure(adventure, attack, false, function (failure) {
  731. adventureSendAll(adventure, swornswords);
  732. });
  733.  
  734. }
  735.  
  736. var pvpFormStore;
  737. function pvpSendBatch(swornswords) {
  738. if (extender_sendAllAction === "none") {
  739. inform("This function is disabled. Please enable it from options.");
  740. return;
  741. }
  742.  
  743. if(!checkCommandPoints()){
  744. inform("Not enough command points. <br>Action cannot execute.");
  745. return;
  746. }
  747.  
  748. if (typeof swornswords == "undefined" || !(swornswords instanceof window.Array)) {
  749. error("An array should be passed to the function. Sending failed.");
  750. return;
  751. }
  752.  
  753. if (swornswords.length == 0) {
  754. inform("All sworn swords are now busy.<br>Action: " + extender_sendAllAction);
  755. pvpFormStore = {}; // clear the store for further use
  756. return;
  757. }
  758.  
  759. var s = swornswords.pop();
  760.  
  761. log("Debuging send all: swornswords: " + swornswords.length + ", " +
  762. "current: " + s.full_name + ", " +
  763. "cooldown: " + s.cooldown + ", " +
  764. "damage: " + s.damage + ", " +
  765. "send? " + !(s.cooldown > 0 || s.damage >= extender_bruteWounds));
  766.  
  767. if (s.cooldown > 0 || s.damage >= extender_bruteWounds) {
  768. pvpSendBatch(swornswords);
  769. return;
  770. }
  771.  
  772. // Store the pvp or replace it
  773. // if it is stored already
  774.  
  775. if (!pvpFormStore) {
  776. pvpFormStore = pvpForm;
  777. } else {
  778. pvpForm = pvpFormStore;
  779. }
  780.  
  781. setSwornSword(s.id);
  782.  
  783. if (!s.modifier) {
  784. resolveModifier(s);
  785. }
  786.  
  787. if (extender_sendAllAction !== "selected") {
  788. userContext.currentActionLabel = s.modifier;
  789. }
  790.  
  791. pvpLaunch(function(success) {
  792. pvpSendBatch(swornswords);
  793. });
  794. }
  795.  
  796. function resolveModifier(s) {
  797. if (s.modifier) {
  798. log("Modifier already set.");
  799. return;
  800. }
  801. // Calculate what attack shoild we use if there ain't any
  802. var max = Math.max(s.calc_battle, s.calc_trade, s.calc_intrigue);
  803. if (max == s.calc_intrigue) {
  804. if(extender_intrigueTrain && extender_intrigueTrain != "intrigue"){
  805. s.modifier = extender_intrigueTrain;
  806. }else{
  807. s.modifier = "spy";
  808. }
  809. } else if (max == s.calc_trade) {
  810. if(extender_tradeTrain && extender_tradeTrain != "trade"){
  811. s.modifier = extender_tradeTrain;
  812. }else{
  813. s.modifier = "barter";
  814. }
  815. } else {
  816. if(extender_battleTrain && extender_battleTrain != "battle"){
  817. s.modifier = extender_battleTrain;
  818. }else{
  819. s.modifier = "fight";
  820. }
  821. }
  822. }
  823.  
  824. function avaSendBatch(swornswords) {
  825. if (extender_sendAllAction === "none") {
  826. inform("This function is disabled. Please enable it from options.");
  827. return;
  828. }
  829.  
  830. if(!checkCommandPoints()){
  831. inform("Not enough command points. <br>Action cannot execute.");
  832. return;
  833. }
  834.  
  835.  
  836. if (typeof swornswords == "undefined" || !(swornswords instanceof window.Array)) {
  837. error("An array should be passed to the function. Sending failed.");
  838. return;
  839. }
  840.  
  841. if (swornswords.length == 0) {
  842. inform("All sworn swords are now busy.<br>Action: " + extender_sendAllAction);
  843. return;
  844. }
  845.  
  846. var s = swornswords.pop();
  847.  
  848. console.debug("Debuging send all: swornswords: " + swornswords.length + ", " +
  849. "current: " + s.full_name + ", " +
  850. "id: " + s.id + ", " +
  851. "cooldown: " + s.cooldown + ", " +
  852. "damage: " + s.damage + ", " +
  853. "region: " + s.garrison_region + ", " +
  854. "subregion: " + s.garrison_subregion + ", " +
  855. "send? " + !(s.damage >= extender_bruteWounds));
  856.  
  857. if (s.damage >= extender_bruteWounds) {
  858. avaSendBatch(swornswords);
  859. return;
  860. }
  861.  
  862. itemCurrentSelection = s;
  863.  
  864. if (extender_sendAllAction !== "selected") {
  865. userContext.currentActionLabel = s.modifier;
  866. }
  867.  
  868. doCampAttack(userContext.campAttackData.id, "skip", function (r) {
  869. console.debug("Anonymous function parameter: ", r);
  870.  
  871. if (r.error) {
  872. avaSendBatch(swornswords);
  873. return;
  874. }
  875.  
  876. if (!r.camp_attack) {
  877. error("Camp data is missing, cannot create new attack.");
  878. return;
  879. }
  880.  
  881. r = r.camp_attack;
  882.  
  883. $.ajax({
  884. url: "/play/camp_attack_create?alliance_id=" + r.target_alliance_id + "&region=" + r.region + "&subregion=" + r.subregion + "&acnew=" + userContext.playerData.ac,
  885. dataType: "JSON",
  886. success: function(a) {
  887. userContext.camp_battle = a.battle;
  888. userContext.camp_trade = a.trade;
  889. userContext.camp_intrigue = a.intrigue;
  890. userContext.campAttackData = a;
  891. startCampAttack(userContext.campAttackData);
  892.  
  893. avaSendBatch(swornswords);
  894. }
  895. });
  896. });
  897. }
  898.  
  899. window.addEventListener("message", receiveMessage, false);
  900. function receiveMessage(event) {
  901. // Do we trust the sender of this message?
  902. if (event.origin !== "https://games.disruptorbeam.com") {
  903. error("Message from untrusted source was rejected.");
  904. console.debug(event);
  905. return;
  906. }
  907.  
  908. //console.debug("Message recieved: ", event);
  909. console.log("Evaluated: ", eval(event.data));
  910.  
  911. }
  912.  
  913. function observable_onkeyup(e){
  914. //console.debug(e);
  915.  
  916. if(e.keyCode === 13 && !e.ctrlKey && !e.shiftKey) {
  917. var observable = $("textarea#observable");
  918. if (!observable) {
  919. error("The observable DOM element was not found in the page.");
  920. return false;
  921. }
  922.  
  923. try {
  924. var cmd = observable.val().split("\n")[0];
  925. eval("extender." + cmd);
  926. } catch (err) {
  927. var prefix = "COMMAND FAILED" + " | " + new Date().toLocaleTimeString() + " | ";
  928. observable.val(prefix + err);
  929. }
  930.  
  931. return false;
  932. }
  933.  
  934. if(e.keyCode === 46){
  935. var observable = $("textarea#observable");
  936. if (!observable) {
  937. error("The observable DOM element was not found in the page.");
  938. return false;
  939. }
  940.  
  941. observable.val("");
  942. return false;
  943. }
  944.  
  945. return true;
  946. }
  947.  
  948. function clearLog(){
  949. sessionStorage.set("clientEntries", []);
  950. log("The client log has been cleared successfully.");
  951.  
  952. $("#logTab").trigger("click");
  953. }
  954.  
  955. var bossChallenger = (function(log, error, questClose, questSubmit, localStorage){
  956.  
  957. var _this = {
  958. init: init,
  959. fight: fight,
  960. persist: persist,
  961. config: config,
  962. addQuest: addQuest,
  963. removeQuest: removeQuest,
  964.  
  965. enabled: true,
  966. bossQuests: []
  967. };
  968.  
  969. function init(o){
  970. try {
  971. _this.bossQuests = localStorage.get("bossQuests", []);
  972.  
  973. _this.config(o);
  974.  
  975. // Relaunch any quests pending...
  976. for (var i = 0; i < _this.bossQuests.length; i++) {
  977. var a = _this.bossQuests[i];
  978. questSubmit(a.quest, a.stage, a.attack, a.chosen, null, null, a.questId);
  979. }
  980. } catch(e) {
  981. error(e);
  982. }
  983. }
  984.  
  985. function config(o){
  986. //console.debug(o);
  987.  
  988. _this.enabled = o.autoBossChallenge;
  989. }
  990.  
  991. function persist(){
  992. localStorage.set("bossQuests", _this.bossQuests);
  993. }
  994.  
  995. // Response, attack
  996. function fight(a, c){
  997. if (a.actions_remaining == void 0 || isNaN(a.actions_remaining)){
  998. log("Not on boss challenge (no actions remaining). Exiting...", "BOSS");
  999. return;
  1000. }
  1001.  
  1002. if(!_this.enabled){
  1003. log("Boss challenge is not automated. Exiting...", "EXTENDER");
  1004. return;
  1005. }
  1006.  
  1007. log("Boss challenge automated. Actions remaining: " + a.actions_remaining + ", " +
  1008. "stage: " + a.stage, "BOSS");
  1009.  
  1010. if(a.stage && a.stage === 1000){
  1011. log("Boss challenge complete. Exiting...", "BOSS");
  1012.  
  1013. _this.removeQuest(a.id);
  1014. _this.persist();
  1015.  
  1016. // Close dialog and pop it from whenever necessary
  1017. questClose(a.symbol, a.id, true);
  1018. return;
  1019. }
  1020.  
  1021. if (a.actions_remaining > 0) {
  1022. questSubmit(a.symbol, a.stage, c, a.chosen, null, null, a.id);
  1023. } else {
  1024. log("No actions remaining! Adjusting...", "BOSS");
  1025.  
  1026. var bossQuest = {
  1027. "quest": a.symbol,
  1028. "stage": a.stage,
  1029. "attack": c,
  1030. "chosen": a.chosen,
  1031. "questId": a.id,
  1032. "timeout": setTimeout(function() {
  1033. questSubmit(a.symbol, a.stage, c, a.chosen, null, null, a.id);
  1034. }, 3 * 4 * 60 * 1000)
  1035. };
  1036.  
  1037.  
  1038. _this.addQuest(bossQuest);
  1039. _this.persist();
  1040.  
  1041. log("Timer running. Fire again in 12 minutes.", "BOSS");
  1042. }
  1043. }
  1044.  
  1045. function addQuest(quest){
  1046. if(quest == void 0){
  1047. error("No quest was passed to add function. Exiting...");
  1048. return;
  1049. }
  1050.  
  1051. var quests = _this.bossQuests;
  1052. for(var i = 0; i < quests.length; i++){
  1053. if(quests[i].questId == quest.questId){
  1054. log("Quest is already made persistable.");
  1055. return;
  1056. }
  1057. }
  1058.  
  1059. quests.push(quest);
  1060.  
  1061. }
  1062.  
  1063. function removeQuest(questId){
  1064.  
  1065. // Remove the quest from the array
  1066. _this.bossQuests = _this.bossQuests.filter(function (el) {
  1067. return el.questId !== questId;
  1068. });
  1069. }
  1070.  
  1071. return _this;
  1072.  
  1073. }(log, error, questClose, questSubmit, localStorage));
  1074.  
  1075. function exSendFavors(favor, characterList){
  1076.  
  1077. var json = {
  1078. favor: favor,
  1079. recipients: characterList
  1080. };
  1081.  
  1082. showSpinner();
  1083.  
  1084. $.ajax({
  1085. type: "POST",
  1086. url: "/play/send_mass_favors",
  1087. data: json,
  1088. dataType: "JSON",
  1089. complete: hideSpinner,
  1090. success: function (a) {
  1091. !0 == a.status
  1092. ? void 0 == a.exceptions ? (doAlert("Message Sent", "Your Raven has been sent."), isWeb() || iosSignal("favors_sent", a.count)) : doAlert("Message Sent", "Your Raven has been sent.<br/><br/>" + a.exceptions + " did not receive a favor as you have already sent them the maximum per day.") : !1 == a.status && ("invalid_favor" == a.reason ? doAlert("Message Center",
  1093. "The selected favor is invalid.") : "not_enough_favors" == a.reason ? doAlert("Message Center", "You have reached your daily favor-giving limit. Your raven was not sent.") : "favor_limit_all" == a.reason ? doAlert("Message Center", "You have already sent the favors daily maximum to these recipients.") : "select_min_player" == a.reason && doAlert("Message Center", "Please select at least one recipient."))
  1094. }
  1095. })
  1096. }
  1097.  
  1098. var worldEvent = (function ($, log, warn, error, submitWorldEventAction, getWorldEventAttackResults, userContext) {
  1099. var _this = {
  1100.  
  1101. delay: 4E3,
  1102. enabled: true,
  1103. timeouts: [],
  1104.  
  1105. get attackers() {
  1106. return localStorage.get("weAttackers", []);
  1107. },
  1108.  
  1109. set attackers(val) {
  1110. localStorage.set("weAttackers", val);
  1111. },
  1112.  
  1113. init: function (o) {
  1114. try {
  1115.  
  1116. this.config(o);
  1117. this.analyze();
  1118.  
  1119. log("World event initialized.", "WORLD EVENT");
  1120.  
  1121. } catch(err) {
  1122. error(err);
  1123. }
  1124. },
  1125.  
  1126. config: function (o) {
  1127. //console.debug(o);
  1128.  
  1129. this.delay = o.worldEventDelay * 1E3 || this.delay;
  1130. this.enabled = o.weManagerEnabled != void 0 ? o.weManagerEnabled : this.enabled;
  1131. },
  1132.  
  1133. dispatch: function () {
  1134. if (!this.enabled) {
  1135. log("This feature has been disabled. Exiting...", "WORLD EVENT");
  1136. return;
  1137. }
  1138.  
  1139. var attackers = this.attackers.filter(function(a){
  1140. return a != void 0;
  1141. });
  1142.  
  1143. for (var i = 0; i < attackers.length; i++) {
  1144.  
  1145. var ss = getSwornSwords(attackers[i]);
  1146. if (!ss) {
  1147. error("Failed to find the sworn sword. Request won't be sent.");
  1148. continue;
  1149. }
  1150.  
  1151. var order = $("#slot_" + i + "_orders").length
  1152. ? $("#slot_" + i + "_orders").val()
  1153. : ss.modifier;
  1154.  
  1155. submitWorldEventAction(ss.id, order, false);
  1156. }
  1157. },
  1158.  
  1159. retrieve: function (ss) {
  1160. if (!this.enabled) {
  1161. log("This feature has been disabled. Exiting...", "WORLD EVENT");
  1162. return;
  1163. }
  1164.  
  1165. if (ss != void 0) {
  1166.  
  1167. if (!ss.id || !ss.action || (ss.full_name == void 0 && ss.name == void 0) || (ss.cooldown == void 0 && ss.cooldown_seconds == void 0)) {
  1168. error("Incorrect object passed, lack of parameters.", "WORLD EVENT");
  1169. console.debug("Debug information, passed sworn sword: ", ss);
  1170. return;
  1171. }
  1172.  
  1173. var cooldown =
  1174. ss.cooldown != void 0 // defined as cooldown
  1175. ? (ss.cooldown !== 0
  1176. ? ss.cooldown // there is a cooldown
  1177. : false) // there ain't a cooldown
  1178.  
  1179. : ss.cooldown_seconds != void 0 // defined as cooldown_seconds
  1180. ? (ss.cooldown_seconds !== 0
  1181. ? ss.cooldown_seconds // there is a cooldown
  1182. : false) // there ain't a cooldown
  1183.  
  1184. : 36E2; // default cooldown of 1hour
  1185.  
  1186.  
  1187. if (!cooldown) {
  1188.  
  1189. getWorldEventAttackResults(ss.id, ss.action, true);
  1190.  
  1191. } else {
  1192.  
  1193. var timeout = {
  1194. id: ss.id,
  1195. name: ss.full_name || ss.name,
  1196. timeout: setTimeout(function () {
  1197.  
  1198. getWorldEventAttackResults(ss.id, ss.action, true);
  1199.  
  1200. }, (cooldown * 1E3) + _this.delay)
  1201. }
  1202.  
  1203. this.timeouts.push(timeout);
  1204. }
  1205.  
  1206. return;
  1207. }
  1208. },
  1209.  
  1210. analyze: function () {
  1211. if (!this.enabled) {
  1212. log("This feature has been disabled. Exiting...", "WORLD EVENT");
  1213. return;
  1214. }
  1215.  
  1216. // dummy data
  1217. var data = {
  1218. sworn_sword_id: 0,
  1219. order: "aid",
  1220. };
  1221.  
  1222. $.ajax({
  1223. url: "/play/world_event_attack",
  1224. data: data,
  1225. success: function (a) {
  1226. console.debug("Analyzing response from the server for the world event action: ", a);
  1227.  
  1228. if (a.challenge && a.challenge.active_swornswords) {
  1229. for (var i = 0; i < a.challenge.active_swornswords.length; i++) {
  1230. _this.retrieve(a.challenge.active_swornswords[i]);
  1231. }
  1232. }
  1233.  
  1234. }
  1235. });
  1236. },
  1237.  
  1238. afterSubmit: function (a, ssId) {
  1239. if (!this.enabled) {
  1240. log("This feature has been disabled. Exiting...", "WORLD EVENT");
  1241. return;
  1242. }
  1243.  
  1244. console.debug("Logging response from the server for sending the sworn sword: ", a);
  1245.  
  1246. if (a.swornsword && a.swornsword.cooldown) {
  1247.  
  1248. this.retrieve(a.swornsword);
  1249.  
  1250. } else if (a.challenge && a.challenge.active_swornswords && a.challenge.active_swornswords.length) {
  1251. var swornswords = a.challenge.active_swornswords;
  1252. for (var i = 0; i < swornswords.length; i++) {
  1253. if (swornswords[i].id !== ssId)
  1254. continue;
  1255.  
  1256. this.retrieve(swornswords[i]);
  1257.  
  1258. }
  1259. }
  1260. },
  1261.  
  1262. afterGet: function (b, ssId) {
  1263. if (!this.enabled) {
  1264. log("This feature has been disabled. Exiting...", "WORLD EVENT");
  1265. return;
  1266. }
  1267.  
  1268. console.debug("Logging response from the server from world event attack: ", b);
  1269.  
  1270. if (b.swornsword && b.action) {
  1271. submitWorldEventAction(b.swornsword.id, b.action, false);
  1272. }
  1273. },
  1274.  
  1275. enlistSS: function () {
  1276.  
  1277. try {
  1278. var attackArray = this.attackers;
  1279. var ss = userContext.setSwornSword;
  1280. if (ss == void 0) {
  1281.  
  1282. if (attackArray.length == 5) {
  1283. attackArray.pop();
  1284. }
  1285.  
  1286. attackArray.unshift(null);
  1287.  
  1288. } else {
  1289.  
  1290. if (attackArray.indexOf(ss.id) > -1) {
  1291. warn("Selected sworn sword is already enlisted for the world event. Exiting...", "WORLD EVENT");
  1292. return;
  1293. }
  1294.  
  1295. if (attackArray.length == 5) {
  1296. attackArray.pop();
  1297. attackArray.unshift(ss.id);
  1298. } else {
  1299. attackArray.push(ss.id);
  1300. }
  1301. }
  1302.  
  1303. this.attackers = attackArray;
  1304. $("#weTab").trigger('click');
  1305.  
  1306. } catch (e) {
  1307. error(e);
  1308. }
  1309.  
  1310. }
  1311. }
  1312.  
  1313. return _this;
  1314.  
  1315. }($, log, warn, error, submitWorldEventAction, getWorldEventAttackResults, userContext));
  1316.  
  1317. // TODO: Implement..
  1318. //var PERSISTABLE = {
  1319. //
  1320. // get queue() {
  1321. // return localStorage.get("productionQueue", []);
  1322. // },
  1323. //
  1324. // set queue(val) {
  1325. // localStorage.set("productionQueue", val);
  1326. // }
  1327. //};

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址